Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How can I have it where I have one IP address that sits on the Internet but many web names? For example, when a hosting company has a shared IP but I get unlimited domain names (along with everyone else on that box).

I have a box on the Internet but I want to point to another machine that holds a different website when someone types in the different www...(it's sitting right next to it in just a different box). Is that all subdomaining? Thank you.

I am the hosting company

share|improve this question
add comment

7 Answers

up vote 13 down vote accepted

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 as attempting to access, and that most modern web browsers have these extensions, so must is a bit too strong.

share|improve this answer
    
so the webserver would see that header and move it to the correct website? Can you have multiple websites on the same port like that? –  johnny Jan 27 '10 at 18:05
1  
That's exactly what it is for. One "server" such as apache, has port 80 of 192.0.32.10 which has many DNS entries, each of which is a "site". The server knows what the desired site is based on the "host" header. –  chris Jan 27 '10 at 18:09
    
but I don't understand where these DNS entries are held...on the server? Since my main port 80 is www.somesiteA.com how will my server forward it to www.somesiteB.com on the same box? –  johnny Jan 27 '10 at 18:18
3  
The DNS is configured to make both names point to the same IP address, where the server is listening. The server receives connections on the same IP and port, but then, when the browser tells it "I want SiteA.com", it knows it needs to give out a different content than when it's asked for SiteB.com. –  Massimo Jan 27 '10 at 18:27
2  
To be even more clear: the two site are distinguished at the HTTP protocol level, not at the TCP/IP level. It's like when someone phones your office and asks to speak with John or Susan: the phone number is the same, but more than one person can use it. –  Massimo Jan 27 '10 at 18:29
show 2 more comments

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.

share|improve this answer
    
+1 host headers! –  William Hilsum Jan 27 '10 at 16:33
    
This should also mention that you need to set multiple DNS entries for your IP address. –  Tadeusz A. Kadłubowski Jan 27 '10 at 16:41
    
@Tadeusz: It is possible to set up wildcard DNS entries, so this is not strictly necessary. –  John Gietzen Jan 28 '10 at 3:56
add comment

In short...

One - Set the DNS entries for your various domains to all point to your box.

Two - As described by others, set up your webserver (you don't say which one) to match on the requested host name.

That way all the requests for all your domains go to the same machine and it's config takes the requested domain and routes it to the right folder containing that site's content.

share|improve this answer
add comment

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.

share|improve this answer
add comment

If I'm reading your question right, you have two different computers sharing an IP address via NAT (Network Address Translation)? If so, you will have to have one site listen on a different port (not 80)--there's no good way I know of to have the router send requests to different computers based on the HTTP "Host" metadata. You're better off just getting a second IP address for your second server.

share|improve this answer
add comment

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.

share|improve this answer
    
or you could other http servers on different ports too of course. –  Chopper3 Jan 27 '10 at 17:16
    
Yes that is also an option. But people aren't used to having to specify a port when they type in a url so I would reserve that solution to a few situations such as an admin interface. –  3dinfluence Jan 27 '10 at 17:20
add comment

It sounds to me from your question like you have a separate physical server for the second website. In that case you will not be able to use a single IP address for the two servers. You can either a) get a second public IP address for your second host or b) set up a smart proxy that forwards requests to different servers on your internal network based on the host headers. I'm pretty sure that b) is possible but I have no real idea of how it works, so you'll have to ask someone else if that is what you are trying to do.

share|improve this answer
add comment

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.