美文网首页
2019-05-27 nginx及时清除缓存

2019-05-27 nginx及时清除缓存

作者: 张大志的博客 | 来源:发表于2019-05-27 17:36 被阅读0次
    proxy_cache_path /etc/nginx/conf.d/cachepath levels=1:2:2 keys_zone=two:10m loader_threshold=300 loader_files=200 max_size=200m inactive=5m;
    upstream cacheups {
          server 127.0.0.1:8080;
    }
    server {
         server_name cache.zhangdazhi.com;
         location / {
             proxy_pass http://cacheups;
             proxy_cache two;
             proxy_cache_valid 200 10m;
             proxy_cache_key $scheme$uri; #定义一个key,访问的域名和uri
             add_header X-cache-Status $upstream_cache_status;
    }
           location ~ /purge(/.*){
                 proxy_cache_purge two $scheme$1;  #当访问的是purge目录下的某个uri时,会清除缓存
    }
    
    }
    [root@hk conf.d]#curl -I cache.zhangdazhi.com/a.txt
    HTTP/1.1 200 OK
    Server: nginx/1.16.0
    Date: Mon, 27 May 2019 09:34:12 GMT
    Content-Type: text/plain
    Content-Length: 5
    Connection: keep-alive
    Last-Modified: Fri, 24 May 2019 07:38:40 GMT
    ETag: "5ce79f80-5"
    X-cache-Status: MISS
    Accept-Ranges: bytes
    
    [root@hk conf.d]#curl -I cache.zhangdazhi.com/a.txt
    HTTP/1.1 200 OK
    Server: nginx/1.16.0
    Date: Mon, 27 May 2019 09:34:16 GMT
    Content-Type: text/plain
    Content-Length: 5
    Connection: keep-alive
    Last-Modified: Fri, 24 May 2019 07:38:40 GMT
    ETag: "5ce79f80-5"
    X-cache-Status: HIT
    Accept-Ranges: bytes
    
    [root@hk conf.d]#curl -I cache.zhangdazhi.com/purge/a.txt
    HTTP/1.1 200 OK
    Server: nginx/1.16.0
    Date: Mon, 27 May 2019 09:34:43 GMT
    Content-Type: text/html
    Content-Length: 279
    Connection: keep-alive
    
    [root@hk conf.d]#curl -I cache.zhangdazhi.com/a.txt
    HTTP/1.1 200 OK
    Server: nginx/1.16.0
    Date: Mon, 27 May 2019 09:34:46 GMT
    Content-Type: text/plain
    Content-Length: 5
    Connection: keep-alive
    Last-Modified: Fri, 24 May 2019 07:38:40 GMT
    ETag: "5ce79f80-5"
    X-cache-Status: MISS
    Accept-Ranges: bytes
    [root@hk conf.d]#nginx -V
    nginx version: nginx/1.16.0
    built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
    built with OpenSSL 1.0.2k-fips  26 Jan 2017
    TLS SNI support enabled
    configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --add-module=/root/ngx_cache_purge  #nginx需要重新编译加上--add-module=/root/ngx_cache_purge模块。github上面有这个模块
    

    相关文章

      网友评论

          本文标题:2019-05-27 nginx及时清除缓存

          本文链接:https://www.haomeiwen.com/subject/qgfktctx.html