×ðÁú¿­Ê±¹ÙÍøµÇ¼

NginxÊðÀí»º´æ¸üÐÂÉèÖà £¬ÊµÊ±ÏìÓ¦Íøվת±ä

nginxÊðÀí»º´æ¸üÐÂÉèÖà £¬ÊµÊ±ÏìÓ¦Íøվת±ä

ÕªÒª£º±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃNginxÊðÀí»º´æ¸üÐÂÉèÖà £¬ÒÔʵÏÖÔÚÍøÕ¾ÄÚÈݱ¬·¢×ª±äʱÄܹ»¼´Ê±ÏìÓ¦¸üР£¬Ìá¸ßÍøÕ¾µÄÐÔÄܺÍÓû§ÌåÑ顣ͬʱ £¬ÎÒÃǽ«ÌṩһЩÊÊÓõĴúÂëʾÀý £¬×ÊÖú¶ÁÕ߸üºÃµØÃ÷È·ºÍÓ¦ÓÃÕâÒ»¹¦Ð§¡£

¼ò½é

NginxÊÇÒ»¿î¸ßÐÔÄܵÄHTTPºÍ·´ÏòÊðÀíЧÀÍÆ÷ £¬±»ÆÕ±éÓ¦ÓÃÓÚ»¥ÁªÍøÓ¦ÓõݲÅÅ¡£ÔÚÊðÀíģʽÏ £¬Nginx¿ÉÒÔ»º´æÍøÕ¾µÄ¾²Ì¬ÄÚÈÝ £¬¼õÇáԴЧÀÍÆ÷µÄ¸ºÔØ £¬¼ÓËÙÍøÕ¾µÄ»á¼ûËÙÂÊ¡£È»¶ø £¬µ±ÍøÕ¾ÄÚÈݱ¬·¢×ª±äʱ £¬NginxĬÈϵÄÉèÖò¢²»»áÁ¬Ã¦¸üлº´æ £¬µ¼ÖÂÓû§¿´µ½µÄÊǾɵÄÒ³ÃæÄÚÈÝ¡£ÎªÏàʶ¾öÕâ¸öÎÊÌâ £¬ÎÒÃÇ¿ÉÒÔͨ¹ýһЩ¼¼ÇɺÍÉèÖÃÀ´ÊµÏÖNginxÊðÀí»º´æµÄ¼´Ê±¸üС£

ÉèÖÃÎļþÐÞ¸Ä

Ê×ÏÈ £¬ÎÒÃÇÐèÒªÐÞ¸ÄNginxµÄÉèÖÃÎļþ £¬ÒÔÈ·±£ÔÚÍøÕ¾ÄÚÈݸüÐÂʱÄܹ»ÊµÊ±Ë¢Ð»º´æ¡£ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔϵÄÉèÖÃÏîÀ´ÊµÏÖ£º

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=10g inactive=60m;
proxy_cache_key "$request_method|$host|$request_uri";
proxy_cache_valid 200 301 302 10m;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;

µÇ¼ºó¸´ÖÆ

ÆäÖÐ £¬proxy_cache_pathÖ¸¶¨ÁË»º´æÎļþµÄ´æ´¢Â·¾¶ºÍ¾ÞϸÏÞÖÆ£»proxy_cache_key½ç˵ÁË»º´æµÄ¼üÃû £¬°ü¹Üÿ´ÎÇëÇóURLÓÐËùת±äʱÄܹ»Ë¢Ð»º´æ£»proxy_cache_validÓÃÓÚÖ¸¶¨HTTPÏìÓ¦Âë200¡¢301¡¢302µÄ»º´æÓÐÓÃÆÚ£»proxy_cache_use_staleÔòÊÇÔÚԴЧÀÍÆ÷·ºÆð¹ýʧʱ £¬ÔÊÐíʹÓÃÓâÆڵĻº´æ¡£

»º´æ¸üйæÔò

ÔÚĬÈÏÇéÐÎÏ £¬NginxÖ»ÓÐÔÚ»º´æÓâÆÚºó²Å»á×Ô¶¯È¥Ô´Ð§ÀÍÆ÷ÇëÇóеÄÄÚÈÝ¡£¶øÎÒÃÇÏ£ÍûÄܹ»ÔÚÍøÕ¾ÄÚÈݱ¬·¢×ª±äʱ £¬¼´Ê±¸üлº´æ¡£ÎªÁËʵÏÖÕâ¸öÄ¿µÄ £¬¿ÉÒÔͨ¹ýÒÔϵÄÉèÖÃÏîÀ´ÉèÖûº´æ¸üйæÔò£º

if ( $request_method = POST ) {
    add_header X-Nginx-Cache "BYPASS";
    proxy_cache_bypass $http_cache_control;
    proxy_no_cache 1;
}

µÇ¼ºó¸´ÖÆ

ÉÏÊöÉèÖý«²¶»ñPOSTÇëÇó £¬²¢ÔÚÏìӦͷÖÐÌí¼ÓX-Nginx-Cache×ֶΠ£¬ÓÃÓÚ±êʶ¸ÃÇëÇóÐèÒªÈƹý»º´æ¡£Í¬Ê± £¬proxy_cache_bypassºÍproxy_no_cacheÖ¸Áȷ±£Õâ¸öÇëÇ󲻻ᱻ»º´æ¡£

¾ç±¾×¼Ê±ÔËÐÐ

ΪÁËʵÏÖ»º´æµÄ׼ʱ¸üР£¬ÎÒÃÇ¿ÉÒÔ±àдһ¸ö¾ç±¾ £¬Í¨¹ý׼ʱʹÃüµÄ·½·¨À´Ë¢ÐÂNginxµÄ»º´æ¡£ÏêϸµÄ¾ç±¾ÄÚÈÝÈçÏ£º

#!/bin/bash

curl -X PURGE http://localhost/page1
curl -X PURGE http://localhost/page2
curl -X PURGE http://localhost/page3

µÇ¼ºó¸´ÖÆ

×¢Öص½ÉÏÊö¾ç±¾ÖÐʹÓÃÁËcurlÏÂÁîÀ´ÏòNginx·¢ËÍPURGEÇëÇó £¬ÒÔɨ³ýÌض¨Ò³ÃæµÄ»º´æ¡£ÎÒÃÇ¿ÉÒÔƾ֤ÏÖÕæÏàÐÎ £¬½«ÐèҪˢлº´æµÄÒ³ÃæURLÌí¼Óµ½¾ç±¾ÖС£È»ºó £¬Ê¹ÓÃ׼ʱʹÃü¹¤¾ß£¨Èçcron£©À´°´ÆÚÔËÐÐÕâ¸ö¾ç±¾ £¬´Ó¶øʵÏÖ»º´æµÄ׼ʱ¸üС£

½áÂÛ

±¾ÎÄÏÈÈÝÁËÔõÑùʹÓÃNginxÊðÀí»º´æ¸üÐÂÉèÖà £¬ÊµÏÖÍøÕ¾ÄÚÈÝת±äʱµÄ¼´Ê±ÏìÓ¦¡£ÎÒÃÇͨ¹ýÐÞ¸ÄNginxµÄÉèÖÃÎļþ £¬ÉèÖûº´æµÄ´æ´¢Â·¾¶ºÍ¸üйæÔò £¬ÒÔ¼°±àд׼ʱÔËÐеĽÅÔ­À´ÊµÏÖÕâÒ»¹¦Ð§¡£ÕâÒ»¹¦Ð§µÄʹÓÿÉÒÔÓÐÓÃÌá¸ßÍøÕ¾µÄÐÔÄܺÍÓû§ÌåÑé £¬ïÔÌ­Óû§ÇëÇó¶ÔԴЧÀÍÆ÷µÄѹÁ¦¡£Ï£Íû¶ÁÕßͨ¹ý±¾ÎĵÄÏÈÈݺÍʾÀý´úÂë £¬¸üºÃµØÃ÷È·ºÍÓ¦ÓÃNginxµÄÊðÀí»º´æ¸üÐÂÉèÖá£

ÒÔÉϾÍÊÇNginxÊðÀí»º´æ¸üÐÂÉèÖà £¬ÊµÊ±ÏìÓ¦Íøվת±äµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

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

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

QR code
ÍøÕ¾µØͼ