【问题标题】:Nginx redirect if not host and if not request uriNginx 重定向,如果不是主机,如果不是请求 uri
【发布时间】:2019-09-08 01:33:54
【问题描述】:

谁能明白为什么下面的 Nginx if 语句不起作用

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
}

在英文中,如果主机不是 subdomain.mydomain.com 并且请求 URI 不是 /.well-known/acme-challenge/* 那么我希望它重定向到另一个域

【问题讨论】:

    标签: nginx nginx-config


    【解决方案1】:

    下面的代码最终对我有用

    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
    }
    

    【讨论】:

      猜你喜欢
      • 2016-12-29
      • 2018-02-21
      • 2015-10-26
      • 1970-01-01
      • 2019-10-25
      • 1970-01-01
      • 2017-06-03
      • 2015-08-28
      • 2012-03-03
      相关资源
      最近更新 更多