I want to use nginx load balancer. The domain servers used in the upstream section use a shared IP.
Suppose the domain name of the load balancer server is load-balancer.com
upstream test_upstream {
server upstream1.com;
server upstream2.com;
}
and
location / {
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://test_upstream/;
proxy_set_header Host $proxy_host;
}
Because the domains use a shared IP, it is very important that the Host value is equal to upstream1.com or upstream2.com. But $proxy_host sets the Host value equal to the upstream name. (In this example, it sets test_upstream in Host).
The header received in the upstream server is as follows:
065.227.015.247.39136-085.083.104.010.00080: GET / HTTP/1.1
Connection: upgrade
Host: test_upstream
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 OPR/98.0.0.0
....
Also, using $host or $http_host instead of $proxy_host will also send the value of load-balancer.com as Host.
Also, if $upstream_http_host or $upstream_http_server or $upstream_http_addr is used, a 404 error will occur.
How to set the Host value correctly?