Home  |  FAQ  |  About  |  Contact  |  View Source   
 
SEARCH:
 
BROWSE:
    My Hood
Edit My Info
View Events
Read Tutorials
Training Modules
View Presentations
Download Tools
Scan News
Get Jobs
Message Forums
School Forums
Member Directory
   
CONTRIBUTE:
    Sign me up!
Post an Event
Submit Tutorials
Upload Tools
Link News
Post Jobs
   
   
Home >  Tutorials >  General Web Development >  Hosting Multiple Domains With One Machine
Add to MyHood
   Hosting Multiple Domains With One Machine   [ printer friendly ]
Stats
  Rating: 4 out of 5 by 12 users
  Submitted: 04/16/02
parker thompson ()

 
Introduction

With the cost of persistent connections at home dropping, it has become possible for just about anyone to host a domain at home. This can be both a fun, and practical experience, providing an interesting challenge as well as experience as a system administrator that can be useful when looking for jobs.

And what’s better than hosting a domain of your own? Hosting two of course.

This tutorial is meant to help you host multiple domains on a single machine using the Apache web server. I had originally intended to include information on IIS, but was unable to obtain a copy of Windows XP Server, which is required to host multiple domains. If you would like more information on how to set up multiple domains using IIS, you can read the about “Host Headers” in the IIS documentation.

Setting Up Your Domains

This tutorial assumes that you have already registered the domains you wish to host, and have them pointed at the ip address which your host will be using. If you have not done this, you should go to your favorite registrar and make it happen. I recommend directnic.com.

After you have done this it will take a couple days, give or take, before “the internet” will be aware of your domains, but you do not need to wait to create the content, or to configure your server.

One trick I use on my Linux workstation is to set an entry in /etc/hosts associating the IP address of my server with the domain I just registered. This will make everything work as it should from my workstation. I believe you can do the same by fiddling around in the advanced tcp/ip properties of your Windows XP network control panel.

The reason you should set a manual entry in /etc/hosts, or make the equivalent change in Windows, is that when you access a website (e.g. www.devhood.com) HTTP 1.1 compliant web browsers (IE 3.0 or higher, Netscape 2.0 or higher) pass the domain as part of the HTTP header. If your browser isn’t passing the domain name, i.e. if you’re just typing in the IP address of your server, you will only be able to see the default domain.

Setting Up Your Server

While this tutorial is written for Windows users, because most of the audience is familiar with the Windows OS, Apache runs on Windows, Linux, many types of Unix, Mac OS, etc. If you’re not using Windows, just get Apache installed and follow the directions below. You’ll just need to figure out the equivalent paths, which shouldn’t be too big of a deal.

For details on how installation differs between OS’s, check out .

Installing

If you don’t have the Apache server, you can get it here. I recommend downloading the .msi installer, but you have some other choices as well.

Upon installing Apache you should be set up to server something, by default a page saying “hey look, I’ve got a fresh install of apache running”, or words to that effect. The first thing we want to do is replace this page with whatever we want as a default. I use my primary domain as a default, so that if ever Apache is confused about what domain it should be serving, it defaults to this. Others prefer to have a page that lists the domains hosted on the machine, letting the user decide where to go.

Creating and Organizing Content

However you wish to organize your sites, the first thing you will need to do isedit the default page, which is located in C:\Program Files\Apache Group\Apache2\htdocs\index.html (using Apache 2.0), in windows, and generally somewhere under /etc or /usr/local/etc on *nix systems. There will be a bunch of files in this directory; you can just remove them all.

I would suggest keeping all of your domains in this folder, each in its’ own sub-folder, though you may put them anywhere you like. Let’s say you wish to create two domains, hostmyown.com and superdupersite.com, as well as having a default page that allows you to choose between the two.

First, create folders named ‘hostmyown’ and ‘superdupersite’ within htdocs\. This is where your content will be housed. You’ll also want to create an index.html in the htdocs folder with whatever default text you wish to be displayed.

Now, stick some content in these folders, and let’s move onto configuring Apache.

Configuring Apache

There’s essentially one file that you’ll need to worry about when configuring Apache. This is httpd.conf. It should be fairly easy to locate.

First we must set up the default site. If you used the .msi installer, you were prompted for this information when you installed, and it is already set up. If you did not you’ll want to find and edit the following lines:

ServerAdmin - your email address, e.g.
ServerName - name of the server, e.g. superduper.com
DocumentRoot - path to the default web directory, e.g. C:\Program Files\Apache Group\Apache2\htdocs\index.html (using Apache 2.0)

Now, we’ve got the defaults in there, let’s set up our two web sites. Scroll to the bottom of the conf file. This is where it all goes down.

First, uncomment (remove the #) in front of the line that reads ‘NameVirtualHosts *’. This will tell Apache that we want it to worry about which hosts our visitors request, and show them different pages based on this information. Alternately, you may bind several IP addresses to a single machine, and differentiate based on this (which is useful, for example, if you have multiple ssl certificates), but that’s a bit beyond the scope of this tutorial.

They also give an example of a virtual host entry:

<VirtualHost *>
    DocumentRoot /www/docs/dummy-host.example.com
    ServerName dummy-host.example.com
</VirtualHost>


which we’re going to copy once for each domain. The * following the VirtualHost directive means that this directive should apply to all IP addresses in use on the machine, which in most cases should just be one.

Modifying the entry should be fairly straightforward. The most important thing you need to understand is that when Apache gets a request for the domain specified by the ServerName directive, it looks for content in the folder specified by the DocumentRoot directive. So, if the ServerName were hostmyown.com, and a request came in for http://hostmyown.com/folder/file.html, and DocumentRoot contained C:\apache\hostmyown\, Apache would look for C:\apache\hostmyown\folder\file.html.

Another note about ServerName. You may use wildcards. For example, I registered parkert.com so that anything with the top level domain parkert.com points to my home machine. I could then differentiate using Apache so that, for example, mp3.parkert.com pointed to one directory (set of pages), and www.parkert.com pointed to another, but I only have one site (parkert.com) so I set ServerName to ‘*.parkert.com’. This tells Apache that all requests with parkert.com as the top level domain should point to the same place.

Conclusion

That’s it. You should now be able to set up an Apache web server, and configure it to server content for as many hosts as you like. I have served 5 at one time on a P90 with 64mb ram, doing about 1-1.5gb of traffic a month with no problems.

For more information on other interesting things you can do with Apache check out apache.org.

My next task is to play around with SOAP and Web Services using Apache. Wish me luck…

Return to Browsing Tutorials

Email this Tutorial to a Friend

Rate this Content:  
low quality  1 2 3 4 5  high quality

Reader's Comments Post a Comment
 
Good tutorial. Organized well and easy to follow.
-- Reid Jonasson, April 21, 2002
 
Interesting tutorial.
-- Brian Simoneau, April 21, 2002
 
One thing that should be mentioned is that this doesn't always work. If you want to have both sites running SSL (via the default port 443), you can't use name-based virtual hosting because SSL handshaking is done before any headers (including the host name) are sent. If you plan to run SSL on both sites, you'll either need to run SSL on a non-standard port for one site, or use different IP addresses for each virtual site. Keep in mind that more than one site can be run off 1 IP address, but SSL-encrypted sites cannot be.
-- Heath Stewart, April 22, 2002
 
Heath,

The reason I didn't include an extensive discussion of SSL here is that I felt it was sort of outside the scope of the tutorial. I also figured that anyone experimenting for the first time with hosting multiple domains would be doing so on a home machine, where ssl is probably not a huge priority.

If anyone is interested in exploring ssl for multiple sites on one machine, you can read about it on apache.org, or check out the O'Reilly Apache book, which is excellent.

As a side note, I was actually what problems you'd have running ssl for multiple domains one the same machine in an interview with a consulting company. In commercial settings it gets used a lot more than you would think, because hardware is so fast you can host many small or medium-sized domains on the same machine. Definitely a good thing to know about.
-- parker thompson, April 22, 2002
 
very helpful and useful!
-- Edward Kim, May 29, 2002
 
Very good tutorial. It had a lot of information. I've looked for related information in the past on the internet and had trouble finding it.
-- Chad Huff, July 14, 2002
 
I never would have thought that this would be so easy. Good tutorial, thanks.
-- Brent Bishop, August 23, 2002
 
thanks for the tutorial. I have a few questions and I am hoping you can help me.

Problem#1: I am running windows xp home(I will have linux soon!). So I am using Apache2.0.44 as a web server.

Problem#2: My ISP blocks port 80.

My goal is to host multiple web sites on my home machine(if I can!).

Is it possible for me to host multiple domains? I have DNS issues since I need to redirect to a different port than port80.

Is windows XP home limiting me?

I need a tutorial that addresses hosting multiple domains with the following:

Windows XP home
Apache
blocked port 80


I believe I am asking alot. Can you give me any suggestions?

Michael
-- michael christoff, May 26, 2003
 
Copyright © 2001 DevHood® All Rights Reserved