0

I'm trying to setup a load balancer with nginx.

The problem i'm having for some reason the variable $host not working for me when i try to use proxy_set_header

When i tried to go to http://proxy.domain.com give me an 404 error, when i check logs give me this.

server: proxy.domain.com, request: "GET / HTTP/1.0", upstream: "http://1.2.3.4:80/", host: "proxy.domain.com"

The IP 1.2.3.4 is the real IP of ss.domain.com if fine here but why give me this http://1.2.3.4:80/ instead of my domain name, because of that give me error 404 and not looking right vhost.

I configured my proxy settings like this:

upstream s3 {
    server ss.domain.com weight=2;
    server vv.domain.com;
}
server {
    listen 80;
    listen [::]:80;
    server_name proxy.domain.com;
    root /var/www/proxy.domain.com/html;

    location / {
        proxy_pass http://s3;
        proxy_set_header    Host               $host;
        proxy_set_header    X-Real-IP          $remote_addr;
        proxy_set_header    X-Forwarded-For    $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Host   $host;
        proxy_set_header    X-Forwarded-Server $host;
        proxy_set_header    X-Forwarded-Port   $server_port;
        proxy_set_header    X-Forwarded-Proto  $scheme;
    }
}   
  • does the traffic/request reaches ss.domain.com or vv.domain.com? can you please share the log? – Sithter Jun 24 at 9:46
  • Yes, is reaches and resolve the IP of the domains, the problem is its transform domain name to IP thats is why its fail. – Erick Jun 26 at 6:43
  • can you please elaborate on how the request fail due to IP address? it's normal that it will resolve DNS to IP address, because it needs to know where does the request send to. is there any webserver (ie nginx) for ss.domain.com and vv.domain.com? if it does, you should be seeing the Host as proxy.domain.com – Sithter Jun 27 at 9:33
  • Its fail because is looking document root of the IP and not for document root of the domain. – Erick Jul 9 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.