Fix incorrect port in upstream requests by forwarding original host and port (#12812)

Replace `Host $host` with `Host $http_host` so the upstream application receives the original host including the port (e.g. `manyfold:8081`).
Add `X-Forwarded-Host` and `X-Forwarded-Port` headers to ensure the Rails app generates correct absolute URLs instead of defaulting to port 80 when running behind nginx on a non-standard port.
This commit is contained in:
ANLO.PO
2026-03-12 14:19:54 +01:00
committed by GitHub
parent 106f9c5adf
commit ee4111f2b0

View File

@@ -101,11 +101,14 @@ server {
location /cable {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host \$host;
proxy_set_header Host \$http_host;
proxy_set_header X-Forwarded-Host \$http_host;
proxy_set_header X-Forwarded-Port \$server_port;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
@@ -118,7 +121,11 @@ server {
location @rails {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host \$host;
proxy_set_header Host \$http_host;
proxy_set_header X-Forwarded-Host \$http_host;
proxy_set_header X-Forwarded-Port \$server_port;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;