Skip to main content

nginx if 多条件判断

因为Nginx中的if语句不允许使用多条件判断,所以需要变通一下,使用变量作为中间值,然后判断这个变量:

set $do_yaf 0;  
if ( $chic_ver = 3 ) {  
    set $do_yaf 1;
}
if (!-e $request_filename) {  
    set $do_yaf "${do_yaf}1"; 
}
if ( $do_yaf = "11" ) {  
    rewrite ^/(.*)$ /index.php/$1 last;
}
location / {  
    include /etc/nginx/conf.d/fastcgi_params;
    if ( $chic_ver = 2 ) {
        proxy_pass http://192.168.172.247:2332;
        break;
    }
    if ( $chic_ver = 3 ) {
        fastcgi_pass unix:/var/php-nginx/14774481332305.sock/socket;
    }
}