nginx if多條件判斷


server {
    listen 10001;
    server_name  qwe.com asd.com;
    set $flag 0;
    if ($http_user_agent ~* "Chrome"){
        set $flag "${flag}1";
    }
    if ($host ~* qwe.com){
        set $flag "${flag}1";
    }
    if ($flag = "011"){
        rewrite ^.+ http://asd.com:10001/test2;
    }
    
    location ^~ /test1 {
        try_files $uri $uri/ /test1/index.html;
        root   html;
        index  index.html index.htm;
        autoindex off;
    }

    location ^~ /test2 {
        try_files $uri $uri/ /test2/index.html;
        root   html;
        index  index.html index.htm;
        autoindex off;
    }
        
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM