From c43599adc28263ca308a7a3688ffb34538fa3932 Mon Sep 17 00:00:00 2001 From: "Mikkel T. Hoegh" Date: Thu, 2 Jul 2026 00:30:26 +0200 Subject: [PATCH] Forward client Host (with port) and scheme in reverse-proxy templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The reverse-proxy templates set `proxy_set_header Host $host`, which normalises the Host header and drops any non-standard port, and they never forward the request scheme. Downstream apps that build absolute URLs from the request (e.g. Drupal, Next.js) therefore emit URLs with the wrong port and scheme when the proxy is published on a non-standard host port such as https://app.local:37103 — the generated links point at https://app.local (port 443) and 404. Use $http_host to preserve the exact Host the client sent (including the port), and forward X-Forwarded-Proto $scheme so the backend knows the public scheme. Both listen ports (80/443) share one server block, so $scheme is correct for either. Applied to all four reverse-proxy variants (proxy, nextjs, storybook, vite); the drupal variant already passes HTTP_HOST/HTTPS via fastcgi_params. Co-Authored-By: Claude Opus 4.8 (1M context) --- context/nextjs/etc/nginx/templates/default.conf.template | 6 ++++-- context/proxy/etc/nginx/templates/default.conf.template | 3 ++- .../storybook/etc/nginx/templates/default.conf.template | 9 ++++++--- context/vite/etc/nginx/templates/default.conf.template | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/context/nextjs/etc/nginx/templates/default.conf.template b/context/nextjs/etc/nginx/templates/default.conf.template index 1e5a53b..9652600 100644 --- a/context/nextjs/etc/nginx/templates/default.conf.template +++ b/context/nextjs/etc/nginx/templates/default.conf.template @@ -6,7 +6,8 @@ server { location / { proxy_pass ${NGINX_PROXY_PASS}; - proxy_set_header Host $host; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } @@ -16,7 +17,8 @@ server { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; - proxy_set_header Host $host; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } diff --git a/context/proxy/etc/nginx/templates/default.conf.template b/context/proxy/etc/nginx/templates/default.conf.template index 4aa6be8..db89a88 100644 --- a/context/proxy/etc/nginx/templates/default.conf.template +++ b/context/proxy/etc/nginx/templates/default.conf.template @@ -6,7 +6,8 @@ server { location / { proxy_pass ${NGINX_PROXY_PASS}; - proxy_set_header Host $host; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # Increase buffer sizes, the defaults can be too tight for diff --git a/context/storybook/etc/nginx/templates/default.conf.template b/context/storybook/etc/nginx/templates/default.conf.template index b266a4a..a335e8c 100644 --- a/context/storybook/etc/nginx/templates/default.conf.template +++ b/context/storybook/etc/nginx/templates/default.conf.template @@ -11,7 +11,8 @@ server { location / { proxy_pass ${NGINX_PROXY_PASS}; - proxy_set_header Host $host; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -26,7 +27,8 @@ server { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; - proxy_set_header Host $host; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } @@ -36,7 +38,8 @@ server { proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; - proxy_set_header Host $host; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } diff --git a/context/vite/etc/nginx/templates/default.conf.template b/context/vite/etc/nginx/templates/default.conf.template index c8a4f15..b1447f3 100644 --- a/context/vite/etc/nginx/templates/default.conf.template +++ b/context/vite/etc/nginx/templates/default.conf.template @@ -6,7 +6,8 @@ server { location / { proxy_pass ${NGINX_PROXY_PASS}; - proxy_set_header Host $host; + proxy_set_header Host $http_host; + proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;