我代理到外部 JSON api 并尝试缓存代理响应。为了确定代理缓存是否正常工作,我添加了
add_header X-Cached $upstream_cache_status;
Run Code Online (Sandbox Code Playgroud)
并始终看到一个MISS值。
我的 nginx 配置位置:
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;
}
Run Code Online (Sandbox Code Playgroud)
在此之前我已经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;
Run Code Online (Sandbox Code Playgroud)
www-data 具有读/写访问权限 /var/cache/nginx
我假设proxy_buffering设置为,on因为我没有任何明确的设置。
nginx 配置有效。我已经测试过它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
Run Code Online (Sandbox Code Playgroud)
我已经跟踪了error.log和access.log并且我没有看到任何可以表明缓存不起作用的原因。
我从代理响应中获得的标头:
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
Run Code Online (Sandbox Code Playgroud)
我被困在这一点上。我不知道还有什么会导致 nginx 无法缓存。请求上没有任何缓存破坏,例如唯一的查询参数,每个请求的 url 都是一致的。除了将标头设置为缓存尝试结果之外,我不知道还有其他任何方法可以记录代理缓存正在执行的操作。
推特救援:https : //twitter.com/btucker/status/899309118137057286
proxy_cache_valid any 48h;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2947 次 |
| 最近记录: |