
nginx 反向代理后端并缓存数据的方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
proxy_cache_path /data/cache/nginx levels=1:2 keys_zone=cache1:100m inactive=1d max_size=2g;//最大占用2G空间
location ^~ / {
//代理所有的域名根目录下的请求,包括静态资源
proxy_pass http://127.0.0.1:3100/;
proxy_cache_key $host$uri$is_args$args;
proxy_redirect off;
proxy_set_header Host $host;
proxy_cache cache1;
#状态为200、302的缓存1天
proxy_cache_valid 200 302 1d;//200 302状态码缓存1天
#状态为301的缓存2天
proxy_cache_valid 301 2d;//301状态码缓存2天
proxy_cache_valid any 1m;//1分钟
#浏览器过期时间设置8小时
expires 8h;
#忽略头部禁止缓存申明,类似与CDN的强制缓存功能
proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie";
#在header中插入缓存状态,命中缓存为HIT,没命中则为MISS
add_header Nginx-Cache "$upstream_cache_status";
}
💘 相关文章
- Nginx使用Memcached缓存加速wordpress,秒开网站
- 卸载腾讯云监控插件的方法
- freebsd Unknown user: 目录名.的解决方法
- 最简单的出生年月,姓名八字算命方法
- 前端开发人员必备-手机浏览器强制刷新缓存
- debian 9 安全升级到Debian 10的方法
- 手动更新p*a*s*s*w*a*l*l的方法
- -bash: dig: command not found的解决方法
- 老是放屁的原因,以及调理的方法
- Configure nginx to only allow cloudflare's IP to connect to the server shell script