From 665f924e9e194c16c0259617948aae0738cd94d6 Mon Sep 17 00:00:00 2001 From: Boris Djurdjevic Date: Fri, 24 Jan 2020 13:50:35 +0100 Subject: [PATCH] Add proxy protocol support for X-Forwarded-Port Fixes https://github.com/kubernetes/ingress-nginx/issues/4951 --- rootfs/etc/nginx/lua/lua_ingress.lua | 1 - rootfs/etc/nginx/template/nginx.tmpl | 6 ++++++ test/e2e/settings/proxy_protocol.go | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/rootfs/etc/nginx/lua/lua_ingress.lua b/rootfs/etc/nginx/lua/lua_ingress.lua index f0b8e761c2..83106425af 100644 --- a/rootfs/etc/nginx/lua/lua_ingress.lua +++ b/rootfs/etc/nginx/lua/lua_ingress.lua @@ -105,7 +105,6 @@ end -- phases or redirection function _M.rewrite(location_config) ngx.var.pass_access_scheme = ngx.var.scheme - ngx.var.pass_server_port = ngx.var.server_port ngx.var.best_http_host = ngx.var.http_host or ngx.var.host if config.use_forwarded_headers then diff --git a/rootfs/etc/nginx/template/nginx.tmpl b/rootfs/etc/nginx/template/nginx.tmpl index 5ee1795163..64c213e30a 100755 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -1032,7 +1032,13 @@ stream { set $proxy_upstream_name {{ buildUpstreamName $location | quote }}; set $proxy_host $proxy_upstream_name; set $pass_access_scheme $scheme; + + {{ if $all.Cfg.UseProxyProtocol }} + set $pass_server_port $proxy_protocol_server_port; + {{ else }} set $pass_server_port $server_port; + {{ end }} + set $best_http_host $http_host; set $pass_port $pass_server_port; diff --git a/test/e2e/settings/proxy_protocol.go b/test/e2e/settings/proxy_protocol.go index 82e0722907..fc696313da 100644 --- a/test/e2e/settings/proxy_protocol.go +++ b/test/e2e/settings/proxy_protocol.go @@ -68,7 +68,7 @@ var _ = framework.IngressNginxDescribe("Proxy Protocol", func() { Expect(err).NotTo(HaveOccurred(), "unexpected error reading connection data") body := string(data) Expect(body).Should(ContainSubstring(fmt.Sprintf("host=%v", "proxy-protocol"))) - Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-port=80"))) + Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-port=1234"))) Expect(body).Should(ContainSubstring(fmt.Sprintf("x-forwarded-for=192.168.0.1"))) }) })