Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nginx] Pass request port to real server #453

Closed
danielqsj opened this issue Mar 16, 2017 · 6 comments · Fixed by #454
Closed

[nginx] Pass request port to real server #453

danielqsj opened this issue Mar 16, 2017 · 6 comments · Fixed by #454

Comments

@danielqsj
Copy link
Contributor

If nginx ingress controller is behind some loadbalancer like haproxy, which redirect other port (not 80 or 443) to nginx ingress controller.
So request may looks like http://host:port. But nginx set Host and X-Forwarded-Host as $host, which without port like host. Therefore when real server send redirects to client requests, the url looks like http://host/redirect_url instead of correct url http://host:port/redirect_url.
If using $http_host instead of $host, the correct port will be passed to real server.

@aledbf
Copy link
Member

aledbf commented Mar 16, 2017

@danielqsj we already pass this information with the header X-Forwarded-Port

@danielqsj
Copy link
Contributor Author

@aledbf Thanks for your reply.
But in my environment, the http_x_forwarded_port always be null. So X-Forwarded-Port will be the $server_port which is 443 (listened by nginx) not the real port (listened by haproxy).
Here is my environment:

client <-> kube-proxy <-> haproxy (used to redirect port, in tcp mode) <-> nginx ingress controller <-> real server

Will there be some misconfigurations?

@danielqsj
Copy link
Contributor Author

@aledbf The problem seems that nginx behind tcp mode proxy of haproxy can only see haproxy's IP. And haproxy can not rewrite http head if using tcp mode.
In this scenario, I find only $http_host contain the correct port. Is there better solution ?

@aledbf
Copy link
Member

aledbf commented Mar 20, 2017

@danielqsj the problem with $http_host is that could be blank but $host always contains a value. I think instead of choosing one of the variables we can use map directive like:

    map $http_host $best_http_host {
        default          $http_host;
        ''               $host;
    }

@danielqsj
Copy link
Contributor Author

@aledbf Great idea. I will fix it. Thank you a lot.

@danielqsj
Copy link
Contributor Author

@aledbf I have fixed this PR #454 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants