![Nginx 代理缓存过期太快](https://linux22.com/image/673620/Nginx%20%E4%BB%A3%E7%90%86%E7%BC%93%E5%AD%98%E8%BF%87%E6%9C%9F%E5%A4%AA%E5%BF%AB.png)
我使用 nginx 1.9.9 作为 Gravatar 的代理(将头像的等待时间从 300ms 缩短到 15ms )。但是,缓存在几分钟后就过期了,而我指定它过期时间为 7 天。几分钟后,我就收到了标头X-Proxy-Cache: EXPIRED
。
配置如下:
proxy_cache_path /var/www/gravatar-cache levels=1:2 keys_zone=gravatar:8m inactive=7d use_temp_path=off max_size=1000m;
proxy_cache_key "$scheme$request_method$host$request_uri";
server {
listen 443 ssl http2;
server_name [hidden];
access_log off;
ssl_certificate [hidden];
ssl_certificate_key [hidden];
location /avatar/ {
expires 365d;
proxy_cache gravatar;
proxy_cache_valid any 7d;
proxy_pass https://secure.gravatar.com;
proxy_ignore_headers Cache-Control;
proxy_hide_header link;
proxy_hide_header source-age;
proxy_hide_header content-disposition;
proxy_hide_header via;
proxy_hide_header x-varnish;
proxy_hide_header accept-ranges;
proxy_hide_header last-modified;
add_header Cache-Control public;
add_header X-Proxy-Cache $upstream_cache_status;
}
}
是不是配置有问题?
谢谢!
答案1
$ curl -vv https://en.gravatar.com/userimage/...jpeg -o /dev/null 2>&1 | egrep 'Expires|Cache-Control'
< Expires: Wed, 23 Dec 2015 20:17:02 GMT
< Cache-Control: max-age=300
我认为它尊重Expires
标题。