nginx清除缓存ngx_cache_purge

来源:互联网 发布:剑网三捏脸数据图 编辑:程序博客网 时间:2024/06/14 06:06
nginx ip:172.18.3.184 web服务 ip:172.18.11.247

ngx_cache_purge模块github下载地址及使用说明

https://github.com/FRiCKLE/ngx_cache_purge/


一:nginx安装

yum install -y patch unzip gcc openssl openssl-devel pcre pcre-develtar fxz nginx-1.7.8.tar.gztar fxz ngx_cache_purge-2.2.tar.gzcd nginx-1.7.8./configure --prefix=/usr/local/nginx --add-module=../ngx_cache_purge-2.2/ --with-http_stub_status_module --with-http_ssl_modulemake && make install

二:nginx.conf

http {    include       mime.types;    default_type  application/octet-stream;    proxy_cache_path  /tmp/cache  keys_zone=tmpcache:10m;        sendfile        on;    keepalive_timeout  65;    server {        listen       80;        server_name  localhost;        location / {                proxy_pass http://172.18.11.247;                proxy_read_timeout     2000s;                proxy_set_header        Host $host;                proxy_set_header        X-Real-IP $remote_addr;                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;                proxy_next_upstream http_502 http_504 error timeout invalid_header;                proxy_cache        tmpcache;                proxy_cache_key    $uri$is_args$args;        }        location ~ /purge(/.*) {            allow              all;            deny               all;            proxy_cache_purge  tmpcache $1$is_args$args;        }            location ~ \.(gif|jpg|jpeg|png|bmp|ico)$ {            proxy_set_header Host  $host;            proxy_set_header X-Forwarded-For  $remote_addr;            proxy_pass http://172.18.11.247;            proxy_cache tmpcache;            proxy_cache_key $uri$is_args$args;            add_header  OpenCDN-Cache "$upstream_cache_status";   #测试时可以查看cache状态            proxy_cache_valid 200 304 12h;            expires 1d;          }}

三:测试

/usr/local/nginx/sbin/nginx -s reload[root@purge cache]# curl --head 172.18.3.184/resources/style/common/css/images/ItemsIco02.pngHTTP/1.1 200 OKServer: nginx/1.8.1Date: Wed, 30 Nov 2016 15:16:20 GMTContent-Type: image/pngContent-Length: 3775Connection: keep-aliveETag: W/"3775-1411717259000"Last-Modified: Fri, 26 Sep 2014 07:40:59 GMTExpires: Thu, 01 Dec 2016 15:16:20 GMTCache-Control: max-age=86400OpenCDN-Cache: HITAccept-Ranges: bytes[root@purge cache]# curl --head 172.18.3.184/purge/resources/style/common/css/images/ItemsIco02.pngHTTP/1.1 200 OKServer: nginx/1.8.1Date: Wed, 30 Nov 2016 15:16:40 GMTContent-Type: text/htmlContent-Length: 292Connection: keep-alive
四:注意   404的时候注意配置文件
proxy_cache_key
proxy_cache_purge两个的一致性


0 0
原创粉丝点击