我正在尝试使用 proxy_pass 重定向 POST 请求。
这是我的完整服务器配置(2 台服务器):
# default server with all my subdomains
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name *.example.com;
passenger_enabled on;
rails_env production;
root /home/admin/rails/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 to manage redirects
server {
listen 80;
server_name example.com;
# pages to redirect to apps.$host
location /app { return 301 $scheme://apps.$host; }
location /app/iphone { return 301 $scheme://apps.$host/iphone; }
location /legal/about { return 301 $scheme://apps.$host/legal/about; }
...
# pages to redirect to cloud or services
location /cloud/signup {
if ($request_method = GET) { return 301 $scheme://cloud.$host/home/new; }
if ($request_method = POST) {
proxy_pass $scheme://services.$host/users/create;
}
}
}
当我运行 CURL POST 时:
curl -X POST --data '' http://example.com/cloud/signup?format=json
我收到 502 Bad Gateway。
因此我查看了日志,完整的错误消息是:
2016/01/08 12:13:37 [错误] 20714#0:*4 没有定义解析器来解析 services.example.com,客户端:52.254.44.3,服务器:example.com,请求:“POST /cloud/signup?format=json HTTP/1.1”,主机:“example.com”
请注意,我对 services.example.com 的 GET 重定向正在正常工作。
我在代理中遗漏了什么?