Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As I understand it, when you request a url from a website using your browser, it asks the DNS server that the OS is pointing at if it knows the ip address that relates to the dns-name of the server; then if the DNS server finds the server requested, it returns the ip so that the browser can request the url from the webserver.

Considering at this point that the browser requests the URL using the ip address of the server and not the dns-name, how does the webserver (Apache2) know how to return correct VirtualHost, that is associated with the dns-name?

My head tells me that it has something to do with the browser headers, but I'm not completely certain of this.

Note: Here's a related solution

share|improve this question
up vote 3 down vote accepted

An HTTP request has a number of headers, not just the requested path. One of these headers (the Host: header) is the hostname which you requested (so "unix.stackexchange.com" for unix.SE). Apache looks at this and serves the request appropriately.

As a side note: HTTPS used to be restricted to one certificate per IP, because the Host: header is encrypted. Until the server gets that header, it wouldn't know which certificate to send, but it can't get the header until it gets the request (which requires the certificate). This was solved in TLS through the Server Name Indication extension, which adds something like the Host header in the initial handshake.

share|improve this answer

HTTP Virtual hosts work by using the HTTP server as a "proxy server" for itself, and the browser is sending the host header which is used to identify the target virtual host.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.