fastcgi_cache_bypass and 502 Bad Gateway

Dayo nginx-forum at
Fri Feb 11 18:15:34 MSK 2011

kaspars Wrote:
> if ($http_cookie ~*
> "comment_author_|wordpress_(?!test_cookie)|wp-post
> pass_" ) {
>   set $donot_cache 1;
> }

AFAIK, the '$donot_cache ' you set here will not contain anything
outside the if block. and therefore your no_cache test will always be
done on an empty variable.

Variable scopes are not documented and only trial and error and fumbling
in the dark reveals stuff.

Would be great if they just had global scopes so that once it is set, it
is there to be used everywhere. However, I think I read something
negative once on this from Maxim Dounin (who seems to be one of the
devs) so I think no matter how much we might want this sort of thing, it
will not happen.

A bit of a pain but that is how it is and most of us don't know enough
to fill in the gaps in the documentation.

I had a similar problem and had to use the 3rd party lua module to run
the test in a way that the variable set was available after:,161969,168394#msg-168394

In your case, why not just use 'fastcgi_no_cache  
$cookie_COOKIE-1$cookie_COOKIE-2$cookie_COOKIE-3' and skip the whole
'if' test?

The advice is to avoid using 'if' unless absolutely required. See:

Posted at Nginx Forum:,173795,174161#msg-174161

More information about the nginx mailing list