美文网首页
nginx缓存

nginx缓存

作者: zusie | 来源:发表于2018-01-22 10:40 被阅读0次

缓存策略

  1. 对于不经常更新的静态文件,建议缓存时间设置为1个月以上
  2. 对于经常需要更新并且更新频繁的静态文件,可以将缓存时间设置短一些
  3. 对于动态文件,建议设置缓存时间为0

常规缓存设置

proxy_cache search-cache;
proxy_cache_revalidate on;
proxy_cache_valid 10m;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache_lock on;
add_header X-Cache-Status $upstream_cache_status;

忽略后端设置cache-contorl

proxy_ignore_headers Cache-Control Set-Cookie;
proxy_cache_valid any 30m;

缓存post请求

proxy_cache_methods GET HEAD POST;

缓存动态内容

设置Cache-Control

bypass cache

#当cookie或者url_args中设置了此项值则不使用缓存
proxy_cache_bypass $cookie_nocache $arg_nocache;

default cache key

proxy_cache_key $scheme$proxy_host$uri$is_args$args;

使用Cookie作为缓存的一部分

proxy_cache_key $cookie_jessionid$scheme$proxy_host$uri$is_args$args;
配置示例
proxy_cache search-cache;
proxy_cache_revalidate on;
proxy_cache_key $scheme$proxy_host$uri$is_args$args$cookie_jsessionid;
proxy_cache_valid 10m;
proxy_ignore_headers Cache-Control Set-Cookie;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
proxy_cache_lock on;
add_header X-Cache-Status $upstream_cache_status;

相关文章

网友评论

      本文标题:nginx缓存

      本文链接:https://www.haomeiwen.com/subject/ueqlaxtx.html