Skip to content

Commit

Permalink
Merge pull request #4956 from djboris9/proxy-protocol-port
Browse files Browse the repository at this point in the history
Fix proxy protocol support for X-Forwarded-Port
  • Loading branch information
k8s-ci-robot authored Jan 26, 2020
2 parents 5eddf10 + 665f924 commit 2f8cbeb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 0 additions & 1 deletion rootfs/etc/nginx/lua/lua_ingress.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/settings/proxy_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
})
})

0 comments on commit 2f8cbeb

Please sign in to comment.