Why is proxy_set_header Host $host; no longer work

2019-04-23 17:30发布

问题:

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?

回答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".



标签: nginx proxy