
原始站点的静态文件的 HTTP Response Headers 里没有 Expires 和 Cache-Control ,于是在代理的时候指定了 7 天的缓存:
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml|txt|pdf)$ { proxy_pass_header Server; proxy_http_version 1.1; proxy_set_header Connection ""; set $cache_key_scheme $scheme; set $cache_key $cache_key_scheme://$host$uri$is_args$args; proxy_set_header Host static.example.com; proxy_cache c1; proxy_cache_key $cache_key; proxy_ignore_headers X-Accel-Expires Expires Cache-Control; proxy_cache_valid 200 301 302 7d; proxy_cache_valid 403 404 500 0s; add_header X-Cache-Status "$upstream_cache_status"; proxy_pass http://origin_http; } 但是测试的时候发现,才过了几分钟就会看到 X-Cache-Status 的值是 EXPIRED。
NGINX 版本是 1.11.*,会是哪些方面的原因呢?
1 tumb8r 2016-08-12 20:13:12 +08:00 via iPhone expires 30d; |
2 Snitchley OP @tumb8r 你的意思是说,只有 proxy_cache_valid 200 301 302 7d; 还不够,还要同时加上相同时间的 expires 7d; ? |
4 AntonChen 2016-08-12 20:36:33 +08:00 via iPhone 楼主设置的是反向代理在 nginx 上缓存的缓存时间,而非客户端 |
5 Snitchley OP 在 Server Fault 上找到了一个接近的问题: http://serverfault.com/questions/744969/nginx-proxy-cache-expires-too-soon 但是我遇到的问题是源站根本就没有 Expires 或者 Cache-Control 的情况下,缓存依然几分钟就过期了。 |
6 millken 2016-08-24 10:58:56 +08:00 可能是 cache zone 设得太小导致 nginx 使用 LRU 淘汰了以前的一些缓存。 |