proxy_cache_bypass and proxy_no_cache

Igor Sysoev igor at sysoev.ru
Mon Dec 10 11:23:15 UTC 2012


On Dec 10, 2012, at 14:15 , amodpandey wrote:

> Thank you :) This one worked.
> 
> I would like to take this opportunity to share the exact problem I had.
> 
> I am using sticky module for some app version targetting. Plus I have
> enabled proxy cache. The sticky module works in a way that it first let the
> upstream handle the weights and according to which server catered the
> response it set cookie with server info hash. So the response that is cached
> is without cookie.
> 
> So in this case even proxy_no_store $http_set_cookie does not work. So the
> only way I could think was to change the caching behaviour to cache only
> requests with my cookie.
> 
> There is only proxy_no_store ( proxy_store does something else ) so I need
> to negate the value, if set. Here the map helped me to achieve the same.
> 
> But I wish there could have been a straight forward way.
> 
> I had this followup question 
> 
> Why we need to have proxy_cache_bypass and proxy_no_cache else
> nginx: [warn] "proxy_no_cache" functionality has been changed in 0.8.46, now
> it should be used together with "proxy_cache_bypass"

By default nginx does not cache response with Set-Cookies header. So to
force to cache such response you should set:
proxy_ignore_headers  Set-Cookie;

As to your problem, it's better to resolve it on upstream side by setting 
X-Accel-Expires: 0
for the first response without Cookie, and
X-Accel-Expires: a_number_of_seconds_to_cache
for response with cookies.

Also you should $http_cookie_cache variable to 
proxy_cache_key


--
Igor Sysoev



More information about the nginx mailing list