1

I am trying to proxy_pass in nginx with the following configuration:

location /abc_service { proxy_pass http://127.0.0.1:3030; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; }

But I am getting /abc_service as prefix in my application(rails application running on port 3030). For Ex: I am getting '/abc_service/users/sign_in' which should be '/users/sign_in'

I want to remove this prefix.

It was working fine in apache with :

ProxyPass /abc_service http://localhost:3030 timeout=300 KeepAlive=On ProxyPassReverse /abc_service/ http://localhost:3030/

Satyam Singh
  • 113
  • 5

1 Answers1

2

The operation of proxy_pass is explained in nginx documentation: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass

A request URI is passed to the server as follows:

If the proxy_pass directive is specified with a URI, then when a request is passed to the server, the part of a normalized request URI matching the location is replaced by a URI specified in the directive:

location /name/ {
    proxy_pass http://127.0.0.1/remote/;
}

If proxy_pass is specified without a URI, the request URI is passed to the server in the > same form as sent by a client when the original request is processed, or the full normalized request URI is passed when processing the changed URI:

location /some/path/ {
    proxy_pass http://127.0.0.1;
}

So, you need to use this:

location /abc_service
{
    proxy_pass       http://127.0.0.1:3030/;
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;
}
Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63