Move proxy variables into their own file

And include them in base nginx.conf. No-one should be bind mounting
nginx.conf but if they are, they can include that file now too.
This commit is contained in:
Jamie Curnow committed 2026-11-16 21:34:48 +10:00
1 parent 55845ce3f3
commit 144de80d40
2 files changed
+37 -30

No files matched your search

@@ -0,0 +1,34 @@
# Variables used by conf.d/include/proxy.conf, conf.d/include/assets.conf and the
# generated host configs. nginx.conf includes this file just before the custom
# http_top.conf, so maps there can redefine these variables. For an nginx.conf kept
# from an older release, which has no such include, the startup script loads it
# through conf.d/*.conf instead (prepare/40-dynamic.sh).
# 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
map $host $forward_scheme {
default http;
}
# Handle upstream X-Forwarded-Proto and X-Forwarded-Scheme header
map $http_x_forwarded_proto $x_forwarded_proto {
"http" "http";
"https" "https";
default $scheme;
}
map $http_x_forwarded_scheme $x_forwarded_scheme {
"http" "http";
"https" "https";
default $scheme;
}
+3 -30
View File
@@ -52,37 +52,7 @@ http {
# Dynamically generated resolvers file
include /etc/nginx/conf.d/include/resolvers[.]conf;
# 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
map $host $forward_scheme {
default http;
}
# Handle upstream X-Forwarded-Proto and X-Forwarded-Scheme header
map $http_x_forwarded_proto $x_forwarded_proto {
"http" "http";
"https" "https";
default $scheme;
}
map $http_x_forwarded_scheme $x_forwarded_scheme {
"http" "http";
"https" "https";
default $scheme;
}
# Real IP Determination
# Local subnets:
set_real_ip_from 10.0.0.0/8;
set_real_ip_from 172.16.0.0/12; # Includes Docker subnet
@@ -93,6 +63,9 @@ http {
real_ip_header X-Real-IP;
real_ip_recursive on;
# $forward_host, $forward_scheme and $x_forwarded_*, before http_top.conf so it can redefine them
include /etc/nginx/conf.d/include/proxy-variables.conf;
# Custom
include /data/nginx/custom/http_top[.]conf;