I'm trying to figure out how to configure a reverse proxy in nginx when the endpoint is in a root context:
http://frontend.com/mylink
proxy forwards to http://10.0.0.2:8000/
Unfortunately I can't change the context of the application at http://10.0.0.2:8000
, so I'm trying to figure out a workaround in nginx for this issue. The following configuration usually works fine when there is a context, but doesn't work in the situation above:
location /mylink {
proxy_pass http://10.0.0.2:8000;
proxy_redirect http://10.0.0.2:8000 /mylink;
port_in_redirect off;
}
Any ideas what I'm missing here?
I think if you change it to:
Notice the
/
on theproxy_pass
line, this causes the matched part of yourlocation
not to be sent to the server.For reference, see http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass:
As your location and proxy_pass don't have a trailing slash the normalized URI won't see the
/mylink
part cut properly nor the proxy_redirect default behaviour append it. Simply use this :