×ðÁú¿­Ê±

NginxÐéÄâÖ÷»úÓÅ»¯ÉèÖã¬ÌáÉýÍøÕ¾ÐÔÄÜ

nginxÐéÄâÖ÷»úÓÅ»¯ÉèÖã¬ÌáÉýÍøÕ¾ÐÔÄÜ

ÔÚ¾ÙÐÐÍøÕ¾¿ª·¢ºÍ°²ÅŵÄÀú³ÌÖУ¬ÓÅ»¯ÉèÖÃÊÇÌá¸ßÍøÕ¾ÐÔÄܵÄÒªº¦»·½ÚÖ®Ò»¡£Nginx×÷Ϊһ¿î¸ßÐÔÄܵÄWebЧÀÍÆ÷ºÍ·´ÏòÊðÀíЧÀÍÆ÷£¬Í¨¹ýºÏÀíµÄÐéÄâÖ÷»úÉèÖÿÉÒÔ³ä·ÖÑéÕ¹ÆäÓÅÊÆ£¬Ê¹ÍøÕ¾Ô½·¢¸ßЧÎȹÌ¡£±¾ÆªÎÄÕ½«ÏÈÈÝһЩNginxÐéÄâÖ÷»úµÄÓÅ»¯ÉèÖÃÒªÁ죬²¢ÌṩÏìÓ¦µÄ´úÂëʾÀý¡£

ºÏÀíÉèÖüàÌý¶Ë¿Ú

Ê×ÏÈ£¬ÎÒÃÇÐèҪ˼Á¿Ñ¡ÔñÒ»¸öºÏÊʵļàÌý¶Ë¿Ú¡£NginxĬÈϼàÌý80¶Ë¿Ú£¬µ«ÈôÊÇÓÐÆäËûÈí¼þÕ¼ÓÃÁ˸ö˿Ú£¬»òÕßÐèҪͬʱÔËÐжà¸öÍøÕ¾£¬¾ÍÐèÒªÐÞ¸ÄĬÈÏÉèÖá £¿ÉÒÔͨ¹ý¸Ä±älistenÖ¸ÁîµÄÖµÀ´Ð޸ļàÌý¶Ë¿Ú¡£ÀýÈ磬½«¶Ë¿ÚÐÞ¸ÄΪ8080£º

server {
    listen 8080;
    ......
}

µÇ¼ºó¸´ÖÆ

¿ªÆôgzipѹËõ

ÆôÓÃgzipѹËõ¿ÉÒÔÓÐÓüõС´«ÊäµÄÊý¾ÝÁ¿£¬Ìá¸ßÍøÕ¾µÄÏìÓ¦ËÙÂÊ¡ £¿ÉÒÔͨ¹ýÔÚÐéÄâÖ÷»úÉèÖÃÖÐÌí¼ÓÒÔÏ´úÂëÀ´ÆôÓÃgzipѹËõ£º

server {
    gzip on;
    gzip_min_length 1024;
    gzip_types text/plain text/css application/javascript application/json;
    ......
}

µÇ¼ºó¸´ÖÆ

ÒÔÉÏÉèÖÃÌåÏÖµ±ÏìÓ¦Êý¾ÝÁè¼Ý1024×Ö½Úʱ£¬²Å»áÆôÓÃgzipѹËõ¡£Í¬Ê±£¬Ö»ÓÐtext/plain¡¢text/css¡¢application/javascriptºÍapplication/jsonÕ⼸ÖÖÀàÐ͵ÄÎļþ²Å»á¾ÙÐÐѹËõ¡£

ÉèÖûº´æ

ºÏÀíÉèÖûº´æ¿ÉÒÔïÔÌ­¶Ôºó¶ËЧÀÍÆ÷µÄÇëÇó´ÎÊý£¬Ìá¸ßÍøÕ¾µÄÏìÓ¦ËÙÂÊ¡ £¿ÉÒÔͨ¹ýÒÔÏ´úÂëÉèÖÃNginx»º´æ£º

server {
    # ÉèÖûº´æ·¾¶ºÍ¾Þϸ
    proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m;

    # »º´æÉèÖÃ
    proxy_cache my_cache;
    proxy_cache_valid 200 302 12h;
    proxy_cache_valid 404 1m;

    # ÊðÀíÉèÖÃ
    location / {
        proxy_pass http://backend_server;
        proxy_cache_use_stale off;
        proxy_cache_bypass $http_cache_control;
        add_header Cache-Control no-store;
    }
}

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂëÖУ¬proxy_cache_pathÖ¸ÁîÓÃÓÚÉèÖûº´æ·¾¶ºÍ¾Þϸ£¬proxy_cacheÖ¸ÁîÓÃÓÚÖ¸¶¨Ê¹ÓÃÄĸö»º´æ£¬proxy_cache_validÖ¸ÁîÓÃÓÚÉèÖûº´æµÄÓÐÓÃʱ¼ä¡£

ÆôÓÃHTTP/2

HTTP/2ÊÇÐÂÒ»´úµÄHTTPЭÒ飬ÓëHTTP/1Ïà±È¾ßÓиü¸ßµÄ²¢·¢ÐÔºÍÐÔÄÜ¡ £¿ÉÒÔͨ¹ýÒÔÏ´úÂ뿪ÆôHTTP/2£º

server {
    listen 443 ssl http2;
    ......
}

µÇ¼ºó¸´ÖÆ

ÒÔÉÏ´úÂëÖУ¬Í¨¹ýÔÚlistenÖ¸ÁîÖÐÌí¼Óhttp2²ÎÊýÆôÓÃHTTP/2¡£

ÉèÖ÷´ÏòÊðÀí

Nginx×÷Ϊ·´ÏòÊðÀíЧÀÍÆ÷³£ÓÃÀ´¸ºÔØƽºâºÍÌṩ»º´æ¹¦Ð§£¬¿ÉÒÔͨ¹ýÒÔÏ´úÂëÉèÖ÷´ÏòÊðÀí£º

upstream backend {
    server backend_server1 weight=3;
    server backend_server2;
    ......
}

server {
    location / {
        proxy_pass http://backend;
        ......
    }
}

µÇ¼ºó¸´ÖÆ

ÒÔÉÏÉèÖÃÖУ¬upstreamÖ¸ÁîÓÃÓÚ½ç˵ºó¶ËЧÀÍÆ÷¼¯Èº£¬¿ÉÒÔƾ֤ÏÖʵÐèÒªÉèÖÃȨÖØ¡£locationÖ¸ÁîÖеÄproxy_passÓÃÓÚÖ¸¶¨·´ÏòÊðÀíЧÀÍÆ÷µÄµØµã¡£

×ܽ᣺

±¾ÎÄÏÈÈÝÁËһЩNginxÐéÄâÖ÷»úµÄÓÅ»¯ÉèÖÃÒªÁ죬°üÀ¨ºÏÀíÉèÖüàÌý¶Ë¿Ú¡¢¿ªÆôgzipѹËõ¡¢ÉèÖûº´æ¡¢ÆôÓÃHTTP/2ºÍÉèÖ÷´ÏòÊðÀí¡£ÕâЩÓÅ»¯ÉèÖÿÉÒÔÌáÉýÍøÕ¾µÄÐÔÄܺÍÎȹÌÐÔ£¬ÈÃÓû§»ñµÃ¸üºÃµÄÌåÑé¡£ËäÈ»£¬ÏêϸµÄÉèÖÃÒªÁ컹Ҫƾ֤ÏÖÕæÏàÐÎÀ´Ï¸»¯µ÷½â¡£

Ï£Íûͨ¹ý±¾ÎĵÄÏÈÈݺÍʾÀý´úÂ룬¶ÁÕßÄܹ»¸üºÃµØÃ÷È·NginxÐéÄâÖ÷»úÓÅ»¯ÉèÖõÄÏà¹Ø֪ʶ£¬²¢ÔÚÏÖʵӦÓÃÖмÓÒÔÔËÓá£

ÒÔÉϾÍÊÇNginxÐéÄâÖ÷»úÓÅ»¯ÉèÖã¬ÌáÉýÍøÕ¾ÐÔÄܵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿