How do you have one IP address and many websites?

Solution 1:

It's part of the HTTP 1.1 protocol.

Specifically, the HTTP 1.1 protocol includes a header called "host:" which specifies which web site on a particular server the client is attempting to access.

So, if snoopy.net and woodstock.org both share 192.0.32.10 and your browser is trying to get content from http://snoopy.net/doghouse the specific http request would look like:

GET /doghouse HTTP/1.1
Host: snoopy.net

If the desired url is http://woodstock.org/seeds the request would look like

GET /seeds HTTP/1.1
Host: woodstock.org

In both cases, there would be a tcp socket between your computer and port 80 of the server. The server would know to get content from /var/www/snoopy.net or /var/www/woodstock.org/ based on the Host header.

There would be other headers for cookies and other stuff like browser type and allowed content, but the "Host" header specifically is what allows the web server to know which virtual web site is desired.

There's more in the RFC2616.

This is also why https sites must** have their own IP address -- the ssl key exchange and certificate verification take place prior to the http transaction, so the http server won't know to give out the certificate for "woodstock.org" or "snoopy.net" when it receives an https connection on port 443 of 192.0.32.10.


edit

** in the comments Grawity points out that there are extensions to SSL in the TLS spec that allow the server to know which web site the user is attempting to access, and that most modern web browsers have these extensions, so must is a bit too strong.

Solution 2:

There is something that all modern browser send along with the request, called the "Host:" Header.

The actual request firefox sends for this page is:

Host: superuser.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

As you can see, the

Host: superuser.com
bit identifies the website in question.

In IIS and Apache, you can configure Virtual Web Sites that only accept requests from a specific IP/Host combination.

As for your particular issue, you will have to read up on how your particular hosting company wants you to request the configuration.


Solution 3:

The technique for hosting more than one domain/subdomain on a single IP address/host is called virtual hosts. The http get request contains the domain name that the requests is for which allows the web server to match up the request with a particular virtual domain.

If you have multiple physical hosts internally with just one external IP then you'll want to look into setting up reverse proxy to forward the requests to the correct machine/internal IP address.


Solution 4:

The feature on your webserver is normally called 'virtual hosts'. Once you point the dns entries to point to that one IP address (as mentioned in the other answers) the server will then server the different sites depending on what the requested host is.

As far as pointing to another box goes. You can configure redirects in most of the web servers if you're expecting to get the query first. If you're talking about subdomains then all you do is point each of the sub domains to a different ip address.

i.e. host.com -> IP 1 then www.host.com -> IP 2 and mail.host.com -> IP 3

If you want more specific answers you need to say what web server software on what operating system you are running.

You might find ServeFault is a better place for this question.