
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,秒开网站
- register nginx systemctl service
- openlitespeed/litespeed禁止访问文件夹和文件的方法
- nginx: [emerg] unknown directive "set_real_ip_from"的解决方法
- directadmin的安装折腾及更改directadmin为nginx记录
- 正確瀏覽器ipv6網站的方法
- 解决路由器ip变动的方法
- 最简单的出生年月,姓名八字算命方法
- nginx "ssl_stapling" ignored, issuer certificate not found for certificate解决方法
- nginx 无缝停机添加模块