nginx清除緩存ngx_cache_purge

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-devel
tar fxz nginx-1.7.8.tar.gz
tar fxz ngx_cache_purge-2.2.tar.gz
cd nginx-1.7.8
./configure --prefix=/usr/local/nginx --add-module=../ngx_cache_purge-2.2/ --with-http_stub_status_module --with-http_ssl_module
make && 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.png
HTTP/1.1 200 OK
Server: nginx/1.8.1
Date: Wed, 30 Nov 2016 15:16:20 GMT
Content-Type: image/png
Content-Length: 3775
Connection: keep-alive
ETag: W/"3775-1411717259000"
Last-Modified: Fri, 26 Sep 2014 07:40:59 GMT
Expires: Thu, 01 Dec 2016 15:16:20 GMT
Cache-Control: max-age=86400
OpenCDN-Cache: HIT
Accept-Ranges: bytes

[root@purge cache]# curl --head 172.18.3.184/purge/resources/style/common/css/images/ItemsIco02.png
HTTP/1.1 200 OK
Server: nginx/1.8.1
Date: Wed, 30 Nov 2016 15:16:40 GMT
Content-Type: text/html
Content-Length: 292
Connection: keep-alive
四:注意   404的時候注意配置文件
proxy_cache_key
proxy_cache_purge兩個的一致性


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章