【问题标题】:Nginx only replace root domain (keep subdomain)Nginx 只替换根域(保留子域)
【发布时间】:2021-04-26 14:30:29
【问题描述】:

我目前有这个域:

https://api.app.com/content.

现在我想将所有传入的 url 重定向到:

https://api.app-2.com/content.

所以我只想替换根域(子域和目录必须继承)。这甚至可以通过 nginx 重写吗?

【问题讨论】:

    标签: ubuntu nginx url-rewriting


    【解决方案1】:

    您是否考虑过从旧域到新域的简单重定向?

    server {
      listen 80;
      server_name foo.old-domain.com;
    
      # Redirect everything to the new domain
      return 301 http://foo.new-domain.com$request_uri;
    }
    
    server {
      listen 80;
      server_name foo.new-domain.com;
    
      location / {
        # Print the URL you're visiting
        add_header Content-Type text/plain;
        return 200 "URL: $uri";
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-06
      • 1970-01-01
      • 1970-01-01
      • 2016-06-17
      • 2021-02-01
      • 2021-12-23
      • 1970-01-01
      相关资源
      最近更新 更多