【问题标题】:nginx redirect one URL to another on the same servernginx 将一个 URL 重定向到同一服务器上的另一个 URL
【发布时间】:2014-01-20 03:28:46
【问题描述】:

所以我有一个响应一个 URL 的 nginx 配置,但现在它应该从那个 URL 重定向到另一个 URL(域名)。

重定向到仍然是同一服务器的不同域 URL 的最佳方法是什么?

编辑: 我尝试使用所有标志返回 301/302,并重写 ^ [新 URL],但它们都创建了一个重定向循环。

谢谢。

【问题讨论】:

    标签: redirect url-rewriting nginx


    【解决方案1】:

    你需要有点具体,但我会试着把一个一般规则作为开始,我们将从example1.com重定向到example2.com

    server {
      listen 80;
      server_name example1.com;
      return 301 http://example2.com$request_uri;
    }
    server {
      listen 80;
      server_name example2.com;
      location / {
        #handle the location
      }
    }
    

    如果您提供更多信息,我会对其进行编辑以符合您的条件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-09
      • 1970-01-01
      • 2014-05-04
      • 1970-01-01
      • 1970-01-01
      • 2016-01-10
      相关资源
      最近更新 更多