Skip to content

Commit c43599a

Browse files
miklclaude
andcommitted
Forward client Host (with port) and scheme in reverse-proxy templates
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) <noreply@anthropic.com>
1 parent dfb72dc commit c43599a

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

context/nextjs/etc/nginx/templates/default.conf.template

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ server {
66

77
location / {
88
proxy_pass ${NGINX_PROXY_PASS};
9-
proxy_set_header Host $host;
9+
proxy_set_header Host $http_host;
10+
proxy_set_header X-Forwarded-Proto $scheme;
1011
proxy_set_header X-Real-IP $remote_addr;
1112
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
1213
}
@@ -16,7 +17,8 @@ server {
1617
proxy_http_version 1.1;
1718
proxy_set_header Upgrade $http_upgrade;
1819
proxy_set_header Connection "Upgrade";
19-
proxy_set_header Host $host;
20+
proxy_set_header Host $http_host;
21+
proxy_set_header X-Forwarded-Proto $scheme;
2022
proxy_set_header X-Real-IP $remote_addr;
2123
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
2224
}

context/proxy/etc/nginx/templates/default.conf.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ server {
66

77
location / {
88
proxy_pass ${NGINX_PROXY_PASS};
9-
proxy_set_header Host $host;
9+
proxy_set_header Host $http_host;
10+
proxy_set_header X-Forwarded-Proto $scheme;
1011
proxy_set_header X-Real-IP $remote_addr;
1112
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
1213
# Increase buffer sizes, the defaults can be too tight for

context/storybook/etc/nginx/templates/default.conf.template

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ server {
1111

1212
location / {
1313
proxy_pass ${NGINX_PROXY_PASS};
14-
proxy_set_header Host $host;
14+
proxy_set_header Host $http_host;
15+
proxy_set_header X-Forwarded-Proto $scheme;
1516
proxy_set_header X-Real-IP $remote_addr;
1617
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
1718

@@ -26,7 +27,8 @@ server {
2627
proxy_http_version 1.1;
2728
proxy_set_header Upgrade $http_upgrade;
2829
proxy_set_header Connection "Upgrade";
29-
proxy_set_header Host $host;
30+
proxy_set_header Host $http_host;
31+
proxy_set_header X-Forwarded-Proto $scheme;
3032
proxy_set_header X-Real-IP $remote_addr;
3133
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
3234
}
@@ -36,7 +38,8 @@ server {
3638
proxy_http_version 1.1;
3739
proxy_set_header Upgrade $http_upgrade;
3840
proxy_set_header Connection "Upgrade";
39-
proxy_set_header Host $host;
41+
proxy_set_header Host $http_host;
42+
proxy_set_header X-Forwarded-Proto $scheme;
4043
proxy_set_header X-Real-IP $remote_addr;
4144
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
4245
}

context/vite/etc/nginx/templates/default.conf.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ server {
66

77
location / {
88
proxy_pass ${NGINX_PROXY_PASS};
9-
proxy_set_header Host $host;
9+
proxy_set_header Host $http_host;
10+
proxy_set_header X-Forwarded-Proto $scheme;
1011
proxy_set_header X-Real-IP $remote_addr;
1112
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
1213

0 commit comments

Comments
 (0)