尊龙凯时人生就是博

Nginx·´ÏòÊðÀí»º´æË¢ÐÂÉèÖà £¬ÊµÊ±¸üÐÂÍøÕ¾¾²Ì¬×ÊÔ´

nginx·´ÏòÊðÀí»º´æË¢ÐÂÉèÖà £¬ÊµÊ±¸üÐÂÍøÕ¾¾²Ì¬×ÊÔ´

СÐò£º

ÔÚWeb¿ª·¢ÖÐ £¬¾²Ì¬×ÊÔ´ÊÇÍøÕ¾Öв»¿É»òȱµÄÒ»²¿·Ö¡£È»¶ø £¬¾­³£¸üеľ²Ì¬×ÊÔ´¿ÉÄܻᵼÖÂÓû§ÔÚ»á¼ûÀú³ÌÖп´µ½¾ÉµÄ°æ±¾»òÕß¼ÓÔØËÙÂʱäÂý¡£½â¾öÕâ¸öÎÊÌâµÄÒ»¸öÓÐÓÃÒªÁìÊÇʹÓÃNginxµÄ·´ÏòÊðÀí»º´æ¹¦Ð§ £¬²¢Í¨¹ýÉèÖÃʵÏÖʵʱ¸üÐÂÍøÕ¾µÄ¾²Ì¬×ÊÔ´¡£±¾ÎĽ«ÏÈÈÝÔõÑùͨ¹ýNginxµÄÉèÖÃÀ´ÊµÏÖÕâÒ»¹¦Ð§¡£

¿ªÆô·´ÏòÊðÀí»º´æ£º

Ê×ÏÈ £¬ÎÒÃÇÐèÒªÔÚNginxµÄÉèÖÃÖпªÆô·´ÏòÊðÀí»º´æ¡£ÕÒµ½NginxµÄÉèÖÃÎļþ£¨Í¨³£Îªnginx.conf£©²¢·­¿ª £¬È»ºóÕÒµ½http½Ú £¬¼ÓÈëÒÔÏÂÉèÖãº

http {
  proxy_cache_path /path/to/cache/directory levels=1:2 keys_zone=cache_zone:10m max_size=10g inactive=60m;
  proxy_temp_path /path/to/temporary/directory;
  proxy_cache_key "$scheme$request_method$host$request_uri";
  proxy_ignore_headers "Cache-Control" "Expires";
  proxy_cache_valid any 10m;
  proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
  
  server {
 ...
 location / {
   proxy_cache cache_zone;
   proxy_pass http://backend-server;
 }
 ...
  }
}

µÇ¼ºó¸´ÖÆ

˵Ã÷£º

proxy_cache_path£ºÉèÖ÷´ÏòÊðÀí»º´æ·¾¶ÒÔ¼°Ïà¹ØÉèÖá£levelsÊÇĿ¼²ã¼¶ £¬keys_zoneÊÇ»º´æÇøÓòµÄÃû³ÆÓë¾Þϸ £¬max_sizeÉèÖûº´æµÄ×î´ó¾Þϸ £¬inactiveÖ¸¶¨»º´æ³¬Ê±Ê±¼ä¡£

proxy_temp_path£ºÉèÖÃÔÝʱĿ¼·¾¶¡£

proxy_cache_key£ºÓÃÓÚÌìÉú»º´ækeyµÄ±äÁ¿ £¬$schemeÌåÏÖÇëÇóЭÒé £¬$request_methodÌåÏÖÇëÇóÒªÁì £¬$hostÌåÏÖÇëÇóµÄÖ÷»úÃû £¬$request_uriÌåÏÖÇëÇóµÄURI¡£

proxy_ignore_headers£ºÖ¸¶¨ÐèÒªºöÂÔµÄÏìӦͷ¡£

proxy_cache_valid£ºÉèÖûº´æµÄÓÐÓÃʱ¼ä¡£

proxy_cache_use_stale£º½ç˵ÔÚ¸üлº´æʱÔÊÐíʹÓ󸯻º´æµÄÇéÐΡ£

ʵʱ¸üо²Ì¬×ÊÔ´£º

ÈôҪʵÏÖʵʱ¸üÐÂÍøÕ¾µÄ¾²Ì¬×ÊÔ´ £¬ÎÒÃÇÐèÒªÔÚºǫ́³ÌÐò»ò¾ç±¾ÖÐÌí¼ÓÌØÁíÍâÂß¼­ £¬ÒÔÔÚÿ´Î¸üо²Ì¬×ÊÔ´ºó·¢³öˢлº´æµÄÇëÇó¡£ÒÔÏÂÊÇÒ»¸ö¼òÆÓµÄʾÀý£º

ÔÚºǫ́³ÌÐò»ò¾ç±¾ÖÐ £¬µ±¾²Ì¬×ÊÔ´±»¸üкó £¬·¢³öˢлº´æµÄHTTPÇëÇó£º

import requests

def refresh_cache():
  url = "http://your-nginx-server/purge-url"
  headers = {"Host": "your-hostname"}
  response = requests.get(url, headers=headers)
  
  if response.status_code == 200:
    print("Cache refreshed successfully!")
  else:
    print("Failed to refresh cache.")

µÇ¼ºó¸´ÖÆ

NginxµÄÉèÖÃÎļþÖÐ £¬ÉèÖõصã·ÓÉÓ뻺´æˢУº

location ~ /purge-url {
  internal;
  proxy_cache_purge cache_zone "$scheme$request_method$host$request_uri$is_args$args";
}

µÇ¼ºó¸´ÖÆ

˵Ã÷£º

location£ºÉèÖô¦Àíˢлº´æÇëÇóµÄ·ÓÉ¡£

internal£ºÌåÏָ÷ÓÉÖ»Äܱ»ÄÚ²¿ÇëÇó»á¼û £¬ÍⲿÇëÇóÎÞ·¨»á¼û¡£

proxy_cache_purge£ºÉèÖÃҪˢеĻº´æÇøÓò¼°Ïà¹Ø²ÎÊý¡£

ͨ¹ýÒÔÉÏÉèÖà £¬µ±·¢³ö´øÓÐX-Purge-Cache: 1µÄGETÇëÇóµ½http://your-nginx-server/purge-urlʱ £¬Nginx»áƾ֤ÇëÇóµÄURIˢжÔÓ¦µÄ»º´æ¡£

ÑéÖ¤£º

ΪÁËÑéÖ¤ÉèÖõÄ׼ȷÐÔ £¬¿ÉÒÔʹÓÃä¯ÀÀÆ÷¡¢Postman»òÀàËƵŤ¾ßÀ´·¢³ö´øÓÐX-Purge-Cache: 1µÄGETÇëÇó¡£ÈôÊÇˢлº´æÀÖ³É £¬Ôٴλá¼û¶ÔÓ¦µÄ¾²Ì¬×ÊԴʱ £¬»á´Óºó¶ËЧÀÍÆ÷»ñÈ¡×îа汾²¢¸üлº´æ £¬È·±£Óû§¿´µ½µÄÊÇ×îеľ²Ì¬×ÊÔ´¡£

½áÂÛ£º

ͨ¹ýNginxµÄ·´ÏòÊðÀí»º´æÉèÖúÍʵʱˢо²Ì¬×ÊÔ´µÄÒªÁì £¬ÎÒÃÇ¿ÉÒÔÌá¸ßÍøÕ¾µÄÐÔÄܺͻá¼ûËÙÂÊ £¬²¢È·±£Óû§Äܹ»ÊµÊ±»ñÈ¡µ½×îеľ²Ì¬×ÊÔ´¡£Õâ¹ØÓÚƵÈÔ¸üеÄÍøÕ¾ÓÈΪÖ÷Òª £¬Í¬Ê±Ò²ÄܼõÇáºó¶ËЧÀÍÆ÷µÄѹÁ¦ £¬Ìá¸ßÍøÕ¾µÄÎȹÌÐԺͿɿ¿ÐÔ¡£Ï£Íû±¾ÎĵÄÏÈÈݶÔÄúÓÐËù×ÊÖú£¡

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

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

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

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

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

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