Nginx缓存配置

  1. http节点中配置缓存

    proxy_cache_path /usr/data/nginx/cache levels=1:2 keys_zone=mycache:10m max_size=10g inactive=60m use_temp_path=off;
    

2.启用配置

location / {
                proxy_pass http://192.168.0.199:8080/;   #来自jsp请求交给tomcat处理
                proxy_redirect off;
                proxy_set_header Host $host;    #后端的Web服务器可以通过X-Forwarded-For>获取用户真实IP
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_cache mycache; 
                proxy_cache_valid 200 302 10m;
                proxy_cache_key    $uri$is_args$args;
                proxy_cache_valid 301 1h;
}

3.介绍
proxy_cache_valid :缓存时间

Syntax: proxy_cache_valid [code ...] time;
Context:  http, server, location

4.清理缓存

location ~ /purge(/.*) {
               allow              127.0.0.1;
               allow              192.168.0.199/24;
               deny               all;
               proxy_cache_purge  cache_one $1$is_args$args;
}

5.访问路径/purge/静态资源地址
psb.png

Last modification:August 12th, 2019 at 09:37 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment