Home > Mobile >  What should be the value of HOST header in a multi layer infrustructure?
What should be the value of HOST header in a multi layer infrustructure?

Time:10-08

I'm trying to understand HOST header better. I came up with a question that I was not sure about its correct answer. Suppose I have a couple of nodes (machines/apps) in between my Servlet container and the internet like below:

Internet ---> first load balancer ---> a monitoring server/application ---> second load balancer ---> my HTTP Servlet contianer

What value should I expect when I call HttpServletRequest.getHeader("host")? Should it be host name of "first load balancer" or host name of "second load balancer"?

CodePudding user response:

The answer is "it depends". It depends on your HTTP servlet container.

If that is configured to listen to the host "your-public-site.com", just as your first load balancer, and the second load balancer has a pool of IP addresses of servers that can answer requests to "your-public-site.com", the request might just look like this:

GET / HTTP/1.1
Host: your-public-site.com

But connected on IP address. The load balanced servers may as well be called "appsrv01.internal.lan", "appsrv02.internal.lan", and so on, and then that is what you'll see.

All of this of course assuming that the second load balancer is configured correctly and knows the host names that the actual servers replying to the requests will respond to.

So: the header you get, is the host name you have configured.

  • Related