Redirect Nginx:将路径重定向到子域,并保留路径末尾和参数

Redirect Nginx:将路径重定向到子域,并保留路径末尾和参数,redirect,nginx,subdomain,Redirect,Nginx,Subdomain,我的目标是重定向此类url: http://example.com/cloud/signup?format=json 致: 所以我想: 删除文件夹/云 添加子域“服务” 更改url的结尾 保留GET/POST/PUT参数(如果有) 我目前的测试是: server { listen 80 default_server; listen [::]:80 default_server; server_name services.example.co

我的目标是重定向此类url:

http://example.com/cloud/signup?format=json
致:

所以我想:

  • 删除文件夹/云
  • 添加子域“服务”
  • 更改url的结尾
  • 保留GET/POST/PUT参数(如果有)
我目前的测试是:

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        server_name services.example.com;
        passenger_enabled on;
        rails_env    production;
        root         /home/admin/app/current/public;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

server {
        listen 80;
        server_name example.com;
        location ~ /cloud(.*) {
                return 301 $scheme://services.example.com/users/create?format=json;
        }
}
它不起作用。
我是否需要创建2台服务器,或者我是否可以只使用主服务器进行重定向?

您无法保持post/put on redirect可能需要使用以下提示:是。但它不会被重新定向。它将是反向代理OK。由于它是一个Rails应用程序,我想我会尝试在Rails路由文件中进行重定向。
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        server_name services.example.com;
        passenger_enabled on;
        rails_env    production;
        root         /home/admin/app/current/public;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
}

server {
        listen 80;
        server_name example.com;
        location ~ /cloud(.*) {
                return 301 $scheme://services.example.com/users/create?format=json;
        }
}