Redirect Nginx使用持久url将域重定向到子域url
我们有一个ruby应用程序,通过passenger+nginx在类似abc.xyz.com的url上提供服务。 现在我们要指向/重定向xyz.com到abc.xyz.com/client/page。 下面是测试代码Redirect Nginx使用持久url将域重定向到子域url,redirect,nginx,Redirect,Nginx,我们有一个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/c
server {
server_name xyz.com;
location / {
return 301 $scheme://abc.xyz.com/client/page;
}
}
但在浏览器URL中,它显示abc.xyz.com/client/page。我们需要xyz.com。获得了解决方案,并且在单个Nginx服务器上运行良好: 将服务器名称条目添加到现有服务器中,如下所示
server_name abc.xyz.com xyz.com;
在下面添加的服务器块中
if ($host = xyz.com)
{
rewrite ^/$ $scheme://$host/client/page/;
}
但现在还有大量工作要做,我需要根据proxy_pass更改此配置。这不正是nginx要求浏览器做的吗?不是xyz.com从abc.xyz.com/client/page获取数据,还是我没有理解问题的重点?重定向是要完成的客户端操作,对吗?@Dilettant是的,xyz.com应该从abc.xyz.com/client/page获取数据。您需要的是反向代理,而不是重定向。有关详细信息,请参阅。@RichardSmith能否根据上述情况发布示例配置。@RichardSmith我尝试了以下配置,但它显示了abc.xyz.com登录页:上游mywebapp1{ip_hash;服务器10.10.10.1服务器10.10.10.2;}服务器{listen 80;server_name xyz.com;location/{proxy_pass;proxy_redirect default;}}