How to preserve request url with nginx proxy_pass How to preserve request url with nginx proxy_pass nginx nginx

How to preserve request url with nginx proxy_pass


I think the proxy_set_header directive could help:

location / {    proxy_pass http://my_app_upstream;    proxy_set_header Host $host;    # ...}


Just proxy_set_header Host $host miss port for my case. Solved by:

    location / {     proxy_pass http://BACKENDIP/;     include /etc/nginx/proxy.conf;    }

and then in the proxy.conf

    proxy_redirect off;    proxy_set_header Host $host:$server_port;    proxy_set_header X-Real-IP $remote_addr;    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


Note to other people finding this: The heart of the solution to make nginx not manipulate the URL, is to remove the slash at the end of the Copy: proxy_pass directive. http://my_app_upstream vs http://my_app_upstream/ – Hugo Josefson

I found this above in the comments but I think it really should be an answer.