| |
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…
|
|