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,秒开网站
- 快速简单一键搭建nginx quic的环境
- 不会配置nginx?这个在线配置nginx的网站非常方便
- 查看當前使用的shell的多種方法
- nginx "ssl_stapling" ignored, issuer certificate not found for certificate解决方法
- how to do config nginx allow's cloudflare ip's
- nginx反向代理配置演示,包括静态资源处理,百分百成功
- mac os 命令行安装软件的方法
- mysql定時去重的方法
- nginx禁止执行php脚本