2017-04-12 127 views
0
I have cached js,css and html files using nginx to improve web page performance. 

    how can i invalidate nginx cache for specific cache key? 

    I have implemented like follows: 

invalidate URl:http://localhost/invalidate_cached_url/?url=[your_url] - 從nginx反向代理緩存中刪除頁面。 位置^〜/ invalidate_cached_url/{ 允許127.0.0.1; 否認所有; proxy_cache_purge nginx_cache $ arg_url; }使nginx緩存無效

when i start nginx service it is giving error "unknown directive :proxy_cache_purge". 

回答

0

請使用免費模塊https://github.com/FRiCKLE/ngx_cache_purge。使用的 示例:

location/{ 
     proxy_pass  http://127.0.0.1:8080; 

     location ~ /purge(/.*) {  
      proxy_cache_purge cache "$host$1";  
     } 

     location ~* ^.+\.(jpeg|jpg|png|gif|bmp)$ {    
      try_files  $uri @fallback;   
     }   
    } 

    location @fallback { 
     rewrite ^(.*)$ /image.php?id=$1; 
     proxy_pass  http://127.0.0.1:8080; 
    } 
  • test.com/myimage.png - URL添加到緩存
  • test.com/ 吹掃 /myimage.png - URL從緩存中移除