使用nginx重定向post请求
我目前收到如下post请求:使用nginx重定向post请求,nginx,Nginx,我目前收到如下post请求: POST /api/x/y HTTP/1.1 带有请求主体:a=x&b=y等 我想通过以下两种方式之一将请求重定向到另一台服务器: 1. GET x.x.x.x:8888/xy/abc?a=x&b=y 2. POST x.x.x.x:8888/xy/abc with body a=x&b=y 我正在尝试以下两种重定向选项: 1.rewrite ^(.*) http://server/api$request_body redirect; //th
POST /api/x/y HTTP/1.1
带有请求主体:a=x&b=y等
我想通过以下两种方式之一将请求重定向到另一台服务器:
1. GET x.x.x.x:8888/xy/abc?a=x&b=y
2. POST x.x.x.x:8888/xy/abc with body a=x&b=y
我正在尝试以下两种重定向选项:
1.rewrite ^(.*) http://server/api$request_body redirect;
//this is not sending body params
2. return 307 http://server/api?$request_body;
//this is giving me 400
如果您这样做:
location /api/ {
proxy_pass http://x.x.x.x:8888;
}
location /api/x/y/ {
proxy_pass http://x.x.x.x:8888/xy/abc/;
}
然后将代理到example.com/api/x/y/的请求
如果您这样做:
location /api/ {
proxy_pass http://x.x.x.x:8888;
}
location /api/x/y/ {
proxy_pass http://x.x.x.x:8888/xy/abc/;
}
然后将代理到example.com/api/x/y/的请求
请求方法将保持不变,除非您告诉Nginx进行更改。某些标题将不会被传递,除非您告诉Nginx传递它们。您是否尝试过:
return 307http://server/api;代码>。客户端应该使用相同的主体重新尝试帖子。