I want to redirect requests on two conditions using nginx.
This doesn\'t work:
if ($host = \'domain.com\' || $host = \'domain2.com\'){
rewrite ^/(
I had this same problem before. Because nginx can't do complex conditions or nested if statements, you need to evaluate over 2 different expressions.
set a variable to some binary value then enable if either condition is true in 2 different if statements:
set $my_var 0;
if ($host = 'domain.com') {
set $my_var 1;
}
if ($host = 'domain2.com') {
set $my_var 1;
}
if ($my_var = 1) {
rewrite ^/(.*)$ http://www.domain.com/$1 permanent;
}