Skip to content

Commit 2c5821f

Browse files
authored
fix(compose): Preserve the request port in the nginx Host header (#926)
Signed-off-by: Prasanth Baskar <prasanth@8gears.com>
1 parent 48e574d commit 2c5821f

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

config/nginx/proxy.conf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@ client_max_body_size 0;
55
proxy_buffering off;
66
proxy_request_buffering off;
77

8-
proxy_set_header Host $host;
8+
# $http_host forwards the Host header verbatim, port included. $host drops a
9+
# non-default port, and core builds URLs back out of req.Host: the /v2/ token
10+
# challenge realm (src/server/middleware/v2auth/auth.go) and the cross-origin
11+
# check on /c/ both do. With $host, a deploy on PORT_HTTP=8080 hands docker a
12+
# realm of http://localhost/service/token and the push fails against port 80.
13+
# $http_host is empty for Host-less requests (HTTP/1.0, raw probes); fall
14+
# back to $host there so that traffic keeps the pre-existing behavior.
15+
set $forwarded_host $http_host;
16+
if ($http_host = '') {
17+
set $forwarded_host $host;
18+
}
19+
proxy_set_header Host $forwarded_host;
920
proxy_set_header X-Real-IP $remote_addr;
1021
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
1122
proxy_set_header X-Forwarded-Proto $scheme;

0 commit comments

Comments
 (0)