0

I'm trying to redirect POST requests with a proxy_pass.

Here is my full servers config (2 servers):

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

When I run a CURL POST:

curl -X POST --data '' http://example.com/cloud/signup?format=json

I obtain a 502 Bad Gateway.

So I looked at the logs and the full error message is:

2016/01/08 12:13:37 [error] 20714#0: *4 no resolver defined to resolve services.example.com, client: 52.254.44.3, server: example.com, request: "POST /cloud/signup?format=json HTTP/1.1", host: "example.com"

Note that my GET redirect to services.example.com is working.

What did I miss in the proxy ?

alex.bour
  • 111
  • 1
  • 5

0 Answers0