Welcome! Log In Create A New Profile

Advanced

Caching for a location based on cookie

Vinay Y S
January 15, 2010 03:14AM
Hi,
For a given location, I want the requests to be cached only if a particular
cookie is not present. How do I achieve that with nginx?
Currently I'm trying following config

location /album {
if ($cookie_logintoken ~* "") {
set $cache_key $scheme$proxy_host$uri$is_args$args;
}

proxy_pass_header Set-Cookie;
proxy_cache_key $cache_key;
proxy_cache mem_pool;
proxy_cache_valid 200 5m;
proxy_pass http://$backend$uri$is_args$args;

}


Here, if the logintoken cookie is not present in the request, the cache_key
variable is set to a valid key string. If the cookie is present, cache_key
it will be undefined. So I expect the proxy_cache_key directive to not cache
that request. But it seems it still caches the request with empty key. Is
this the expected behavior? Is there any solution this problem?

Also, with "proxy_cache_valid 200 5m;" I expect only 200 responses to be
cached. But I'm seeing 30x responses also getting cached.

*nginx version 0.7.64*

Thanks,
--
Vinay
_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Caching for a location based on cookie

Vinay Y S January 15, 2010 03:14AM

Re: Caching for a location based on cookie

agentzh January 15, 2010 04:12AM

Re: Caching for a location based on cookie

Vinay Y S January 17, 2010 11:42AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 168
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready