Score:0

nginx load balancer cannot send "proxy_host" value correctly

am flag

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?

in flag
If the upstream server share the same IP, what's the point in the load balancer in the first place?
mani avatar
am flag
@gerald-schneider It is used in an anti-censorship method of the Internet
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.