Setting cache parameters via if directives

agentzh agentzh at gmail.com
Tue Feb 1 11:54:03 MSK 2011


On Tue, Feb 1, 2011 at 4:47 PM, agentzh <agentzh at gmail.com> wrote:
> Consider the following config snippet:
>
>    location /test {
>        set $a 3;
>        if ($a = 3) {
>            set $a 4;
>        }
>        echo $a;
>    }
>
> GET /test will give you nothing for nginx 0.7.21 ~ 0.9.4.

Forgot to mention that we've been in favor of ngx_lua's set_by_lua and
rewrite_by_lua directives to do something like this:

    location /test {
        set $a 3;
        set_by_lua $a '
            if ngx.var.a == "3" then
                return 4
            end
        ';
        echo $a;
    }

and GET /test will give you the expected answer, "4" and the
performance remains outstanding especially when you've enabled LuaJIT
2.0 ;)

Cheers,
-agentzh



More information about the nginx mailing list