Pass through forwarded Host & Port
This commit is contained in:
1 parent
5e250f4d72
commit
e2dd61af66
1 file changed
+35
-1
@@ -50,6 +50,38 @@ http {
|
||||
gzip_http_version 1.1;
|
||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
|
||||
|
||||
# X-Forwarded-Host (pass-through, or set)
|
||||
map $http_x_forwarded_host $x_forwarded_host {
|
||||
default $http_x_forwarded_host;
|
||||
"" $http_host;
|
||||
}
|
||||
|
||||
# X-Forwarded-Proto (pass-through, or set)
|
||||
map $http_x_forwarded_proto $x_forwarded_proto {
|
||||
default $http_x_forwarded_proto;
|
||||
"" $scheme;
|
||||
}
|
||||
|
||||
# Set the default port based on X-Forwarded-Proto
|
||||
map $x_forwarded_proto $default_http_port {
|
||||
default 80;
|
||||
"https" 443;
|
||||
}
|
||||
|
||||
# Extract the remote port from the HTTP Host header.
|
||||
# Uses default_http_port from above,
|
||||
# when no port was found in the header.
|
||||
map $http_host $x_remote_port {
|
||||
default $default_http_port;
|
||||
"~^[^\:]+:(?<p>\d+)$" $p;
|
||||
}
|
||||
|
||||
# X-Forwarded-Port (pass-through, or set)
|
||||
map $http_x_forwarded_port $x_forwarded_port {
|
||||
default $http_x_forwarded_port;
|
||||
"" $x_remote_port;
|
||||
}
|
||||
|
||||
# Site
|
||||
server {
|
||||
|
||||
@@ -72,7 +104,9 @@ http {
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:8080;
|
||||
proxy_set_header Host localhost;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-Host $x_forwarded_host;
|
||||
proxy_set_header X-Forwarded-Port $x_forwarded_port;
|
||||
proxy_set_header X-Forwarded-Proto $x_forwarded_proto;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_redirect off;
|
||||
|
||||
Reference in new issue
Block a user