Is there a more elegant way to apply conditions in nginx?

Posted by Ryan Detzel on Server Fault See other posts from Server Fault or by Ryan Detzel
Published on 2012-11-20T10:42:37Z Indexed on 2012/11/20 11:06 UTC
Read the original article Hit count: 203

Filed under:

Is there a better way to do this? I can't find a way to nest or apply boolean operators to conditions in nginx.

Basically if there is a cookie set(non-anonymous user) we want to hit the server. If the cookie is not set and the file exists we want to server the file otherwise hit the server.

        set $test "D";
        if ($http_cookie ~* "session" ) {
            set $test  "${test}C";
        }
        if (-f $request_filename/index.html$is_args$args) {
            set $test  "${test}F";
        }
        if ($test = DF){
            rewrite (.*)/ $1/index.html$is_args$args?
            break;
        }
        if ($test = DCF){
            proxy_pass http://django;
            break;
        }
        if ($test = DC){
            proxy_pass http://django;
            break;
        }
        if ($test = D){
            proxy_pass http://django;
            break;
        }

© Server Fault or respective owner

Related posts about nginx