Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/nginx/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redirect Nginx使用持久url将域重定向到子域url_Redirect_Nginx - Fatal编程技术网

Redirect Nginx使用持久url将域重定向到子域url

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

我们有一个ruby应用程序,通过passenger+nginx在类似abc.xyz.com的url上提供服务。 现在我们要指向/重定向xyz.comabc.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服务器上运行良好:

将服务器名称条目添加到现有服务器中,如下所示

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;}}