4

I see this a lot and I'm not sure how it works, the mechanics behind it. I've been asked if it's possible to host two sites, on the same Windows 2012 server on the same IP address but with different domains.

My question is what (and how does it) allows two different websites on the same IP be accessed by two different domains, for example what (and where) is the mechanism that decides www.a.com shows this and www.b.com shows this when the DNS entires for www.a.com and www.b.com are both 80.80.60.100?

  • I'm sure this has been asked before - but I can't seem to find it? – MrWhite Jan 11 '17 at 10:35
3

Because HTTP request sent from browsers includes the host name. The server is able to identify it and serve the respective content.

In our world we have very limited IPV4 addresses but more websites. A web hosting company usually serves over hundreds of websites from the same server (same IP).

  • So is this a safe practice to use an IP address to create a mysql connection? Server can check the host name and respond respectively. But what about an IP address? – hpaknia Jul 30 at 15:24
1

You can host as many sites as you want from one Server (one IP). All you need is to is to:

  1. Point the A record of the websites (from the DNS settings of the NameServers of the respective websites) that you want to host to the IP of the Server
  2. Create Virtual hosts on the Server.

If you're using an IIS server, you can check out https://support.microsoft.com/en-us/kb/816576

There are different tutorials based on which server you're using. Just search for virtual hosts and the server and you should be good to go!

  • 3
    "Create Virtual hosts" - this doesn't actually answer the question. Specifically, this needs to be a named virtual host. The server can then compare these named virtual hosts against the Host: header in the HTTP request (which contains the domain/hostname) in order to decide which virtual host to serve. – MrWhite Jan 11 '17 at 11:06
  • I was talking more from a developer perspective, searching for it will help someone get the correct path to achieve what the question intends – Karan Shah Jan 11 '17 at 11:10
1

Your server that is listening at that address can decide what to serve up.

if request.host==host1 then
  //Serve site 1
else
...

This was just pseudocode, but it can probably be done with most server side code frameworks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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