【发布时间】:2017-02-15 18:02:14
【问题描述】:
当入站请求是带有 nginx 的 XHR(ajax) 时,我如何禁用缓存(如果可能,对于 Apache)?
XHR 有这个 https 标头:
X-Requested-With : XMLHttpRequest
谢谢
【问题讨论】:
当入站请求是带有 nginx 的 XHR(ajax) 时,我如何禁用缓存(如果可能,对于 Apache)?
XHR 有这个 https 标头:
X-Requested-With : XMLHttpRequest
谢谢
【问题讨论】:
对于 nginx,请尝试以下代码,
...
set $no_cache 0;
...
if ($http_x_requested_with ~* 'XMLHttpRequest') {
set $no_cache 1;
}
...
location ~ \.php$ {
...
fastcgi_no_cache $no_cache;
...
}
...
【讨论】:
fastcgi_cache_bypass $no_cache;。 fastcgi_no_cache 和 fastcgi_cache_bypass 参数的组合提供了对缓存行为的细粒度控制。
It is generally a good idea to avoid if in nginx configuration files whenever possible。如果您有任何方法来调整发送请求的前端,请尝试将当前时间添加为 GET 变量(例如myhost/?1475834405)。由于之前没有请求过该 URL,因此不会使用缓存。
【讨论】: