简述

nginx_cache_purge是nginx的一个三方模块,主要是对nginx生产的缓存(proxy_cache)内容进行清理。

模块github介绍:ngx_cache_purge is nginx module which adds ability to purge content from FastCGI, proxy, SCGI and uWSGI caches.

模块GITHUB链接:https://github.com/FRiCKLE/ngx_cache_purge

安装

nginx_cache_purge是一个三方模块,默认没有编译到nginx中,需要我们手动add进去。

[root@lnmp openresty-1.15.8.2]# ./configure --prefix=/usr/local --user=www --group=www --add-module=/data/software/openresty-1.15.8.2/ngx_cache_purge
[root@lnmp openresty-1.15.8.2]# gmake 
[root@lnmp openresty-1.15.8.2]# gmake install

配置

upstream svr{
    server 192.168.3.1100:8088;
}
server {
    listen  80;
    index index.html;
    server_name dev.nginx.top;

   location / {
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_pass http://svr;
        add_header Cache-Control no-store;

        proxy_cache cache;
        proxy_cache_key    $uri$is_args$args;
        proxy_cache_valid   30m;
        add_header  X-Cache-status "$upstream_cache_status";
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_next_upstream off;
      
     }
     location ~ /purge(/.*) {
        allow        all;
        proxy_cache_purge cache $1$is_args$args;

     }

测试

在你需要删除缓存的uri前加purge就可以了。例如一个有缓存的页面是https://35z.org/10.html,那么删除缓存的时候使用https://35z.org/purge/10.html就可以了。

文章目录