nginx proxy_cache 无法生效问题解决
nginx proxy_cache 是一个比较有用的东西,可以对于系统请求的资源进行cache,可以提升系统的性能
参考玩法
参考资料
- cache zong
proxy_cache_path /data/nginx_caches2 levels=1:2 keys_zone=static_cache1:256m max_size=10g;
- proxy cache 配置
location ~ .*\.(gif|jpg|jpeg|png|css|js|ico|mp4) {
proxy_cache static_cache1;
proxy_cache_key $uri$is_args$args;
expires 30d;
client_body_buffer_size 10M;
client_max_body_size 10G;
proxy_buffering on;
proxy_buffers 1024 4k;
proxy_cache_valid any 48h;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504 http_429;
proxy_read_timeout 300;
add_header X-Proxy-Cache $upstream_cache_status;
proxy_set_header Host $host;
set $cip $remote_addr;
if ($http_x_forwarded_for != "") {
set $cip $http_x_forwarded_for;
}
proxy_set_header X-Forwarded-For $cip;
proxy_pass http://proxy_resource;
}
几个参数说明
很多时候我们需要配置 proxy_cache_valid 以及proxy_buffering on ,同时还需要注意cache zone 的目录是否有权限,比如nginx 使用了默认的nobody 自己手工创建
了文件夹也会出现问题,如果为了简单可以直接proxy_cache_valid 配置any,对于我碰到的问题包含了上边说的几点,但是也会有其他问题,类似的一些,提供开源
项目nginx-proxy 一些东西是很值得参考学习的, 为了方便测试推荐添加下add_header X-Proxy-Cache $upstream_cache_status;
包含一个cache 的请求头,方便分析
问题
说明
多学习官方文档,阅读源码还是比较重要的
参考资料
https://nginx.org/en/docs/http/ngx_http_proxy_module.html
https://www.nginx.com/blog/nginx-caching-guide/
https://stackoverflow.com/questions/9230812/nginx-as-cache-proxy-not-caching-anything
https://www.sheshbabu.com/posts/nginx-caching-proxy/
https://docs.nginx.com/nginx/admin-guide/content-cache/content-caching/
https://github.com/nginx/nginx/blob/master/src/http/modules/ngx_http_proxy_module.c
https://github.com/nginx-proxy/nginx-proxy/issues/241
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 上周热点回顾(2.17-2.23)
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· spring官宣接入deepseek,真的太香了~
2021-08-22 基于cloudevents+easy-rules+centraldogma 进行基于规则的业务开发
2021-08-22 mercurius 基于fastify 的graphql server 以及gateway 服务
2021-08-22 如何测试easy-rules 的spel 表达式
2021-08-22 easy-rules-centraldogma-spring-boot-starter spel 模版格式说明
2020-08-22 odyssey prometheus 监控
2020-08-22 odyssey 试用
2019-08-22 singer tap-minio-csv 使用