12

I used proxy_set_header Host $host; to set the host header to the original request host. In nginx 1.4.1 this was working fine. Now after upgrading to 1.8.0, I'm getting the local IP instead of the host passed by the browser.

Why did this happen and how do I fix it?

3
  • I believe this is caused by a proxy_set_header Host $host; in nginx.conf and seems also to be related to the server_name directive. I've yet to determine exactly how they interact, but I've found setting proxy_set_header Host $host in your location directive, while also omitting the server_name entirely works in our case Commented Jan 18, 2016 at 14:43
  • 1
    Did you ever find a solution? I'm having same problem... 1.7 worked, but latest in ppa (1.12) does not. Nothing I do sends correct host header upstream. Commented Feb 12, 2018 at 22:56
  • 1
    "proxy_set_header Host $http_host" should work Commented Aug 4, 2019 at 21:22

2 Answers 2

4

Use proxy_set_header Host $http_host.

If proxy_set_header Host $host; no longer works, perhaps the meaning/ behavior of $host changed. $http_host just passes along what was sent by the browser.

Sign up to request clarification or add additional context in comments.

8 Comments

Why should he do that?
If proxy_set_header Host $host; no longer works, perhaps because the meaning/ behvaior of $host changed, and proxy_set_header Host $http_host; still works. $http_host just passes along what was sent by the browser.
Thank you for explaining the code you only blurted out. stackoverflow.com/help/how-to-answer
Yeah sorry, didn't have much time back then...and I thought better a quick answer, than no answer at all. ;)
This answer should be reworded to include facts. Right now it just sounds like a guess and a suggestion to try something else out.
|
1

tl;dr; I'm not sure when it changed, but newer versions of nginx -- instead of ssl_protocols ...; -- your conf should be:

proxy_ssl_server_name on; proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

Source: https://stackoverflow.com/a/25330027

===

If you were like me, you were misreading the log files and seeing host=example.com. Instead of this being the host sent to the origin, this seems to mean host-as-defined-in-nginx-conf i.e. virtual host.

(Turning on error_log debug; showed that the host header was being correctly set.)

The log file should also contain an error like "sslv3 alert handshake failure".

1 Comment

Thank you kind stranger from the before times. This answer saved my sanity.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.