我是一个外部JSON API的代理,并试图caching代理响应。 要确定代理caching是否正在工作,我已经添加了
add_header X-Cached $upstream_cache_status;
并总是看到一个MISS值。
我的nginxconfiguration位置:
location /api/tides { proxy_hide_header Cache-Control; proxy_ignore_headers Cache-Control; proxy_cache worldtidecache; proxy_set_header Host www.worldtides.info; proxy_pass https://example.com/api/$query_string; add_header X-Cached $upstream_cache_status; }
在此之前,我已经设置了proxy_cache_path
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=worldtidecache:100m max_size=1g inactive=48h use_temp_path=off;
www-data具有对/var/cache/nginx读/写访问权限
我假设proxy_buffering设置为on因为我没有任何明确的设置。
nginxconfiguration是有效的。 我用nginx -c nginx.conf -ttesting了它nginx -c nginx.conf -t :
╰─sudo nginx -c nginx.conf -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
我已经跟踪了error.log和access.log ,我没有看到任何可以指示为什么caching不起作用的东西。
我从代理响应中得到的标题:
Server: nginx/1.11.13 Date: Sun, 20 Aug 2017 14:01:59 GMT Content-Type: text/json; charset=utf-8 Content-Length: 2976 Connection: keep-alive Content-Encoding: gzip X-Cloud-Trace-Context: 38faabaa5ada170536632bb55a0ddf00;o=1 Vary: Accept-Encoding X-Cached: MISS
我被困在这一点上。 我不知道还有什么会导致nginx不caching。 没有任何caching破坏发生在请求上,像一个唯一的查询参数,这个url在每个请求中是一致的。 除了将标题设置为caching尝试结果之外,我不知道有任何其他方式来logging代理caching正在做什么。
Twitter的救援: https : //twitter.com/btucker/status/899309118137057286
proxy_cache_valid any 48h;