首页 > 网站 > WEB开发 > 正文

nginx 设置缓存

2024-04-27 15:05:24
字体:
来源:转载
供稿:网友
#缓存目录 目录级别 缓存池 有效时间 最大空间PRoxy_cache_path /usr/local/etc/nginx/cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g;location /get_api_post_data { proxy_pass http://127.0.0.1:8888; #代理地址 proxy_set_header Host $host; #header proxy_cache_methods GET HEAD POST; # 缓存方法 proxy_ignore_headers Cache-Control Set-Cookie; #设置客户端缓存 proxy_cache STATIC; #缓存池 proxy_cache_valid 200 1m; #请求为200 缓存一分钟 proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; }

其中proxy_cache_key 默认为hosturi 针对接口缓存,不会因为参数改变而不走缓存 当然也可以自己定义

proxy_cache_key $host$uri$is_args$args; //通过key来hash,定义KEY的值

参考文章 https://www.nginx.com/resources/wiki/start/topics/examples/reverseproxycachingexample/


上一篇:Sublime Text使用

下一篇:redux文档解读

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表