Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

2 Answers 2

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

 
discard

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.