我试图用不同的proxy_keycachingajax请求。
我的常规代理密钥:
proxy_cache_key "$host$request_uri";
我想使用不同的proxy_cache_key作为Ajax请求(与X-Requested-With头一起提供)。
像这样的东西
if ($http_x_requested_with) { proxy_cache_key "$host$request_uri$cookie_SID"; }
我怎样才能做到这一点?
也许这样的事情
首先,将"$host$request_uri"保存到一个带有set的variables中。 然后在里面if改变variables值。 最后使用该自定义variables设置您的proxy_cache_key 。
旁注 :如果你不想得到意想不到的结果,不要使用内部位置。 见IfIsEvil 。
这里的例子:
http { ... server { ... set $cache_key "$host$request_uri"; if ($http_x_requested_with) { set $cache_key "$host$request_uri$cookie_SID"; } proxy_cache_key $cache_key; location / { .... } location /others { ..... } } }