Nginx multiple conditional judgment

problem description

A website binds two domain names to access (123.com abc.com), and then involves a jump problem (123.com to www.123.com abc.com to www.abc.com) and http to https

configuration of Server segment on PC:

set $flag 0;
if ($scheme = http) {

 set $flag "${flag}1";

}

if ($host = "www.123.com") {

set $flag "${flag}1";
}


if ($host = "www.abc.com"){

set $flag "${flag}0";

}

if ($flag ="011"){
 return 301 https://www.123.com$request_uri;
}

if ($flag ="010"){
 return 301 https://www.abc.com$request_uri;
}

configuration in mobile server:

set $flag 0;
if ($scheme = http) {

 set $flag "${flag}1";

}

if ($host = "m.123.com") {

set $flag "${flag}1";
}


if ($host = "m.abc.com"){

set $flag "${flag}0";

}

if ($flag ="011"){
 return 301 https://m.123.com$request_uri;
}

if ($flag ="010"){
 return 301 https://m.abc.com$request_uri;
}

then when you check the configuration, you will prompt
invalid condition "$flag" in Mobile profile

Aug.18,2021

  1. it is recommended to write the jump as 302 when debugging the configuration, otherwise it will be troublesome and misleading when the client cleans up the cache.
  2. does not understand the logic of the configuration. If you just xxx.com jump www.xxx.com , you can CNAME the past directly during DNS parsing (when there is no MX rule), or jump with URL, so that nginx only needs to deal with http jump to https (CNAME scheme), and the latter doesn't even have to do this;
  3. Mobile jump, judge the uA and then jump according to the conditions. It seems that there is no need to separate a configuration file. In addition, it is not recommended to use 301, otherwise you will always move the end after you use the browser to bring down the web page.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb3d29-248d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb3d29-248d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?