Add X-Forwarded-Host header passing

This commit is contained in:
SilverFire - Dmitry Naumenko 2022-04-21 17:33:45 +03:00
parent ea9c2db2a8
commit 1bf47f4dbf
2 changed files with 20 additions and 0 deletions

View file

@ -79,6 +79,13 @@ map $http_x_forwarded_port $proxy_x_forwarded_port {
'' $server_port;
}
# If we receive X-Forwarded-Host, pass it through; otherwise, pass along the
# host the client connected to
map $http_x_forwarded_host $proxy_x_forwarded_host {
default $http_x_forwarded_host;
'' $http_host;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
@ -127,6 +134,7 @@ proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $proxy_x_forwarded_host;
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;

View file

@ -57,6 +57,18 @@ def test_X_Forwarded_Ssl_is_overwritten(docker_compose, nginxproxy):
assert r.status_code == 200
assert "X-Forwarded-Ssl: off\n" in r.text
##### Testing the handling of X-Forwarded-Host #####
def test_X_Forwarded_Host_is_generated(docker_compose, nginxproxy):
r = nginxproxy.get("http://web.nginx-proxy.tld/headers")
assert r.status_code == 200
assert "X-Forwarded-Host: web.nginx-proxy.tld\n" in r.text
def test_X_Forwarded_Host_is_overwritten(docker_compose, nginxproxy):
r = nginxproxy.get("http://web.nginx-proxy.tld/headers", headers={'X-Forwarded-Host': 'foo.bar.baz'})
assert r.status_code == 200
assert "X-Forwarded-Host: web.nginx-proxy.tld\n" in r.text
##### Other headers