From ee4111f2b0ad8c21c9805a8a79565714f826bac3 Mon Sep 17 00:00:00 2001 From: "ANLO.PO" Date: Thu, 12 Mar 2026 14:19:54 +0100 Subject: [PATCH] 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. --- install/manyfold-install.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/install/manyfold-install.sh b/install/manyfold-install.sh index fddaf63c2..b766c7fd5 100644 --- a/install/manyfold-install.sh +++ b/install/manyfold-install.sh @@ -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;