【发布时间】:2018-04-04 17:18:09
【问题描述】:
我有一个单页应用程序,我正在尝试使用查询参数 nocahce=true 绕过 Nginx 缓存以获取第一个响应(HTML 文件)和由它发起的所有后续请求(获取 CSS、JS 等)。
根据this,我可以使用查询参数绕过我的缓存,但它没有按预期工作。
重现问题的步骤:
使用这个缩小的通用配置:
http {
...
proxy_cache_path /var/temp/ levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g;
server {
...
location / {
# Using angularjs.org as an example
proxy_pass https://angularjs.org;
proxy_set_header Host angularjs.org;
proxy_cache STATIC;
proxy_cache_valid 200 10m;
proxy_cache_bypass $arg_nocache;
add_header X-Cache-Status $upstream_cache_status always;
}
}
}
预期:
请求“http://servername”和“http://servername/css/bootstrap”(或http://servername?nocache=true发起的任何其他后续请求)的响应头以绕过缓存,即包含 "X-Cache-Status: BYPASS"。
实际:
“http://servername”的响应头包含“X-Cache-Status: BYPASS”但“http://servername/css/bootstrap”没有,取而代之的是“X-Cache-Status”的值是 HIT/MISS/etc 取决于缓存状态。
我是否以错误的方式使用了 proxy_cache_bypass 或者我需要做更多的事情来实现预期的行为?
谢谢!
【问题讨论】:
标签: nginx caching single-page-application