4

I recently set up a reverse proxy server on some some Docker containers using Nginx and it works as expected. I am reverse proxying on these containers themselves to applications being run on these containers.

I just don’t understand how the server receives the subdomain to decide where the request should be routed to.

As far as I know every domain is resolved by DNS-Servers and returns the IP address of the server, so the client can connect to the target server using the received IP. But apparently the client also appends the domain to the request, is that possible?

I do not have a clear explanation for that, because from my perspective the client connects to the target server using an IP, not a domain.

0

1 Answer 1

3

The Host: header is used.

When any web browser makes a GET request to load a web page it sends along a Host: header that the web server can use for things like name-based virtual hosting and reverse proxies.

While Nginx has some documentation on how this works — under the heading of “Name-based virtual servers” I find the Apache documentation for name-based virtual hosts is a bit clearer in explaining how it all works:

“If the request contains a Host: header field, the list is searched for the first vhost with a matching ServerName or ServerAlias, and the request is served from that vhost. A Host: header field can contain a port number, but Apache always ignores it and matches against the real port to which the client sent the request.”

So it all boils down to the Host: header:

  • DNS Resolution: DNS provides the IP address of the destination host.
  • Host Header: The request being made itself has the Host: header that is then interpreted by the receiving web server to act on… Or ignore… It’s simply a header that can be used.
1
  • A reverse proxy is not limited to using the Host header.
    – harrymc
    Commented Mar 31, 2021 at 20:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .