HAProxy and Nginx on same host are all fun and games. The first one listens on port 443, and the second one on 444, configured as proxy’s backend. Everything works, we go home, right?
wrong
If you happen to run nginx on a different port on a same host, the folder redirects won’t work properly, as nginx will HTTP/301 the living hell to the proper fully-fledged absolute-path URI, and not relative path. (i.e. https://example.com/folder
goes to HTTP/301 https://example.com/folder/
and not HTTP/301 ./folder/
).
What does this mean?
This means that your internal, backend’s port will show up. To the visitor. The port that it doesn’t listen on. The port that is firewalled. Or whatever:
HTTP/301 https://example.com:444/folder/
How to circumvent that?
Add a port_in_redirect off;
in your server block of vhost config file:
https://nginx.org/en/docs/http/ngx_http_core_module.html#port_in_redirect
Thank me later ✌️