@@ -28,6 +28,13 @@ http {
2828 '' $host;
2929 }
3030
31+ # If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
32+ # server port the client connected to
33+ map $http_x_forwarded_port $proxy_x_forwarded_port {
34+ default $http_x_forwarded_port;
35+ '' $server_port;
36+ }
37+
3138 # If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
3239 # scheme used to connect to this server
3340 map $http_x_forwarded_proto $proxy_x_forwarded_proto {
@@ -42,11 +49,32 @@ http {
4249 https on;
4350 }
4451
45- # If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
46- # server port the client connected to
47- map $http_x_forwarded_port $proxy_x_forwarded_port {
48- default $http_x_forwarded_port;
49- '' $server_port;
52+ # If we receive X-Original-Forwarded-Host, use it; otherwise, use
53+ # the value of X-Forwarded-Host
54+ map $http_x_original_forwarded_host $proxy_x_forwarded_host_final {
55+ default $http_x_original_forwarded_host;
56+ '' $proxy_x_forwarded_host;
57+ }
58+
59+ # If we receive X-Original-Forwarded-Port, use it; otherwise, use
60+ # the value of X-Forwarded-Port
61+ map $http_x_original_forwarded_port $proxy_x_forwarded_port_final {
62+ default $http_x_original_forwarded_port;
63+ '' $proxy_x_forwarded_port;
64+ }
65+
66+ # If we receive X-Original-Forwarded-Proto, use it; otherwise, use
67+ # the value of X-Forwarded-Proto
68+ map $http_x_original_forwarded_proto $proxy_x_forwarded_proto_final {
69+ default $http_x_original_forwarded_proto;
70+ '' $proxy_x_forwarded_proto;
71+ }
72+
73+ # If we receive X-Original-Forwarded-Ssl, use it; otherwise, use
74+ # the value of X-Forwarded-Ssl
75+ map $http_x_original_forwarded_ssl $proxy_x_forwarded_ssl_final {
76+ default $http_x_original_forwarded_ssl;
77+ '' $proxy_x_forwarded_ssl;
5078 }
5179
5280 # If we receive X-Request-ID, pass it through; otherwise, pass along the
@@ -71,12 +99,12 @@ http {
7199 proxy_set_header Proxy "";
72100
73101 proxy_set_header X-Real-IP $remote_addr;
74- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
75- proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
76- proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
77- proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
78102 proxy_set_header X-Request-ID $proxy_x_request_id;
79- proxy_set_header X-Forwarded-Host $proxy_x_forwarded_host;
103+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
104+ proxy_set_header X-Forwarded-Host $proxy_x_forwarded_host_final;
105+ proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port_final;
106+ proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto_final;
107+ proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl_final;
80108 proxy_set_header X-Request-Start "t=${msec}";
81109
82110 # Latency headers
0 commit comments