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 d9468ae29f..c937a73478 100755 --- a/rootfs/etc/nginx/template/nginx.tmpl +++ b/rootfs/etc/nginx/template/nginx.tmpl @@ -1021,7 +1021,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"))) }) })