1. 程式人生 > >Nginx 用最快方式讓緩存失效

Nginx 用最快方式讓緩存失效

keys status lis file nbsp nac oot one hub

陶輝103

一般讓及時緩存失效針對nginx官方是收費的 我們可以用第三方模塊 https://github.com/FRiCKLE/ngx_cache_purge技術分享圖片

proxy_cache_path /data/nginx/tmpcache levels=2:2 keys_zone=two:10m loader_threshold=300 
                     loader_files=200 max_size=200m inactive=1m;

server {
    server_name shop**.com.cn;
  listen : 8080;
    root html
/; error_log logs/cacherr.log debug; location ~ /purge(/.*) { proxy_cache_purge two $scheme$1; #這個第三方模塊key必須與下面的location 裏的 proxy_cache_key一致,用於實時清除下面的key緩存 } location /{ proxy_cache two; proxy_cache_valid 200 1m; add_header X-Cache-Status $upstream_cache_status; proxy_cache_key $scheme$uri; proxy_pass http:
//localhost:8012; } }

然後先訪問 crul http://shop**.com.cn:8080/purge/1.txt -I

Nginx 用最快方式讓緩存失效