2

The company that I work for, uses Nginx for Reverse Proxy and Load Balancer, so I just add an another block to nginx.conf file as shown below for the new service, when requesting Nginx server with curl http://10.11.12.15:8080/api Nginx returns 400 Bad Request, however after changing this configuration proxy_set_header Host $http_host:$proxy_port; to proxy_set_header Host $host:$server_port; solved Bad Request problem. But I don't get the point.

I have already read this answers What's the difference of $host and $http_host in Nginx and Practical difference of $http_host and $host.

But there isn't a clear answer for this situation. What is the difference between this headers ?

proxy_set_header Host $http_host:$proxy_port;

proxy_set_header Host $host:$server_port;

Used this block;

 upstream web-service {

    server 10.11.12.13:8080;
    server 10.11.12.14:8080 backup;
  }
  server {

    listen 8080;
    server_name myHost 10.11.12.15;
    location / {

      proxy_pass http://web-service;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header Host $http_host:$proxy_port;  # Throw HTTP 400 Bad Request
  #   proxy_set_header Host $host:$server_port;      # Working solution
    }
  }
fuat
  • 1,484
  • 2
  • 19
  • 25

1 Answers1

1

$http_host already includes port when it's not default. Therefore it errors if you try to add a port again. $host doesn't include a port.

Vlad
  • 3,001
  • 1
  • 22
  • 52