On 20 Jan 2011 04h05 WET, removed_email_address@domain.invalid wrote:
if ($cookie_COOKIE = “”) {
set $cookie_no_cache true;
}
Now it works as “usual”.
Nginx’s “if” is evil and can be even more evil when you use it a bit
more. The code snippet above can only work when being put into the
“server” block rather than the “location” block
Ok. Care to elaborate on that? I think is something that should be
explicitly stated in the IfIsEvil wiki page.
Seems as if I may have spoken too soon on the Lua option.
Now, it does check for the existence of the cookie and set the variable
accordingly, but I am almost drawing the conclusion that proxy_no_cache
and proxy_cache_bypass do not accept user defined variables as input as
whether the extra content from the backend in my case seems to be a hit
or miss affair and it seems the only time I can guarantee that the
content is served from the back end is when I either purge the cache or
run those two against a cookie.
Nginx’s “if” is evil and can be even more evil when you use it a bit
more. The code snippet above can only work when being put into the
“server” block rather than the “location” block
I believe this is a perfect use case for ngx_lua:
location / {
set_by_lua $no_cache ’
if ngx.var.cookie_COOKIE == “” or ngx.var.cookie_COOKIE == nil
then
return 1
end
return “”
';
proxy_cache_bypass $no_cache;
proxy_pass …
}
Actually you can implement even more complicated caching policy this
way because Lua is a turing complete language and also has great
performance
Seems it may be to do with the scope of the user set variables (not
sure) but after moving adding proxy_no_cache and proxy_cache_bypass to
the same location instead of the centrally called ones, It seems to be
working as expected.
The hint was in agentzh’s original post
location / {
set_by_lua $no_cache ’
if ngx.var.cookie_COOKIE == “” or ngx.var.cookie_COOKIE == nil then
return 1
end
return “”
'; proxy_cache_bypass $no_cache;
proxy_pass …
}