简体   繁体   中英

Nginx redirect if not host and if not request uri

Can anyone see why the following Nginx if statements doesn't work

if ($host != subdomain.mydomain.com) {
    set $test  A;
}

if ($request_uri != /.well-known/acme-challenge/(.*?)) {
  set $test  "${test}B";
}

if ($test = AB) {
  rewrite ^/(.*) https://www.anotherdomain/$1 permanent;
  break
}

In English, if the host is not subdomain.mydomain.com and the request URI is not /.well-known/acme-challenge/* then I want it to redirect to another domain

The following code in the end worked for me

if ($host != subdomain.mydomain.com) {
    set $test  A;
}

if ($request_uri !~ /\.well-known) {
      set $test  "${test}B";
}

if ($test = AB) {
  rewrite ^/(.*) https://www.anotherdomain/$1 permanent;
  break
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM