有没有办法让NGINX有一个不同的caching取决于一个cookie的价值?
在我的情况下,我有一个网站(在我的情况下,一个插件),创build一个名为devicePixelRatio的cookie。 这在大多数情况下是1,但是如果你有一个高DPI显示,那么它将等于2(或更多)。 基本上,服务器端根据这个cookie的值(或者是1或者其他)产生不同的网站。 基本上我需要两个caching,一个用于devicePixelRatio = 1,另一个用于devicePixelRatio的其他值。
那可能吗?
非常感谢。
是的,这是可能的。
https://stackoverflow.com/questions/26128412/how-to-extract-some-value-from-cookie-in-nginx
http://nginx.org/en/docs/http/ngx_http_core_module.html#variables
使用客户端请求标头来评估cookie内容。 build立你的caching访问逻辑。
更多信息: https : //serversforhackers.com/nginx-caching/
这是一个起点:
http://syshero.org/post/50053543196/disable-nginx-cache-based-on-cookies
例如,您可以将proxy_cache_path放置在评估cookie内容的if语句中。 伪代码:
if $cookie_devicePixelRatio = 2 proxy_cache_path = /retina/; (or fastcgi_cache_path) else proxy_cache_path = /sd/; (or fastcgi_cache_path)