Fix for changing the upstream Host from $host to $forward_host

($http_host) forwards the raw client Host header, including the port and
any absolute-form URI mismatch, to every upstream and into the asset
cache key
This commit is contained in:
Jamie Curnow committed 2026-11-09 22:09:34 +10:00
1 parent 99678969b3
commit fff2b0d097
3 files changed
+16 -6

No files matched your search

+10 -4
View File
@@ -52,10 +52,16 @@ http {
# Dynamically generated resolvers file
include /etc/nginx/conf.d/include/resolvers[.]conf;
# Preserve the client authority, falling back when a request has no Host header.
map $http_host $forward_host {
default $http_host;
"" $host;
# Forwarded Host: nginx's normalised $host (lowercased, taken from the request line for
# absolute-form requests) plus the client's port, so upstreams that compare Host with
# Origin/Referer on non-standard ports keep working. The port is only carried over when
# the Host header names the same host nginx routed on; otherwise (no Host, absolute-form
# URI naming a different host) it falls back to bare $host. Using $host rather than the
# raw header keeps case variants and mismatched Host values out of upstream requests and
# the asset cache key.
map "$host|$http_host" $forward_host {
"~*^(?<fwd_name>[^|]+)\|\k<fwd_name>(?<fwd_port>:[0-9]+)$" "$host$fwd_port";
default $host;
}
# Default upstream scheme