Proxy cache for php site

lpugoy nginx-forum at
Wed Nov 9 11:02:52 UTC 2011

Maxim Dounin Wrote:
> Yes, nginx won't cache responses with cookies
> unless you 
> specifically ask it to via proxy_ignore_headers
> directive[1].
> Please also note that if you do so, you may want
> to also instruct 
> nginx to hide returned cookies from clients (via
> proxy_hide_header 
> directive[2]), or you'll end up with multiple
> clients with the 
> same cookie.
> Example configuration should look like:
>     proxy_ignore_headers Set-Cookie;
>     proxy_hide_header Set-Cookie;
> Depending on the actual headers your backend
> returns you may also 
> need to ignore other headers as well for cache to
> work, notably 
> Expires and Cache-Control.
> Alternatively, you may want to instruct your
> backend to not return 
> headers which prevent caching.
> [1]
> _headers
> [2]
> eader


Thank you for the explanation. I now understand the problem and it is
now working.

I want to add a condition where if a cookie with the name sess_id is
included in the request, then the cache would be bypassed. I tried the

if ($http_cookie ~* "sess_id") {
  set $no_cache "1";

proxy_no_cache $no_cache;
proxy_cache_bypass $no_cache;

but it doesn't seem to work. What is the correct way to do this? Thank
you very much.

Posted at Nginx Forum:,216756,218066#msg-218066

More information about the nginx mailing list