【问题标题】:Nginx redirect domain to subdomain url with persist urlNginx 使用持久 url 将域重定向到子域 url
【发布时间】:2017-04-17 07:20:15
【问题描述】:

我们有一个ruby 应用程序通过passenger+nginx 在像abc.xyz.com 这样的url 上提供服务。 现在我们想要将 xyz.com 指向/重定向到 abc.xyz.com/client/page。 下面是尝试过的代码

server {
    server_name xyz.com;
    location  / {
         return 301 $scheme://abc.xyz.com/client/page;
    }
}

但在浏览器 URL 中显示 abc.xyz.com/client/page。我们想要 xyz.com。

【问题讨论】:

  • 这不正是nginx要求浏览器做什么吗?而不是 xyz.com 从 abc.xyz.com/client/page 获取数据 - 还是我没有明白问题的重点?重定向是要完成的客户端操作,对吗?
  • @Dilettant 是的,xyz.com 应该从 abc.xyz.com/client/page 获取数据。
  • 您需要反向代理而不是重定向。请参阅this document 了解更多信息。
  • @RichardSmith 您能否根据上述情况发布示例配置。
  • @RichardSmith 我在 conf 下面试过,但它显示 abc.xyz.com 登录页面:upstream mywebapp1 { ip_hash;服务器 10.10.10.1 服务器 10.10.10.2; } 服务器 { 听 80; server_name xyz.com;位置 / { proxy_pass mywebapp1/client/page; proxy_redirect 默认; } }

标签: redirect nginx


【解决方案1】:

得到解决方案并在单个 Nginx 服务器上正常工作:

在现有的基础上添加了如下的服务器名称条目,

server_name abc.xyz.com xyz.com;

在下面添加的服务器块中

    if ($host = xyz.com)
    {
rewrite ^/$ $scheme://$host/client/page/;
}

但现在还有很多工作要做,我需要根据 proxy_pass 更改此配置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-03
    • 2017-06-15
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    • 2017-02-20
    • 2021-11-03
    • 2012-05-25
    相关资源
    最近更新 更多