Here are some additional web sites which you may find useful:
By the way:
Before you begin - setting up your hosts file
You've got to understand about the hosts file. /etc/hosts on UNIX and c:\windows\system32\drivers\etc\hosts on Windows. This file provides a lookup table for a name and IP address. On my machine, this looks like:
## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost 192.168.2.101 laptop 192.168.2.102 powerbook 192.168.2.103 home 192.168.2.104 ali 192.168.2.105 imac 192.168.2.105 striders 192.168.2.105 clanmills 192.168.2.105 heather
So, when you type in the address http://clanmills the browser discovers that the IP address of 'clanmills' as 192.168.2.105 and does a GET on the HTTP Server at that location (on port 80).
Virtual Hosts work because the HTTP Server (Apache on a Mac) sees RequestHeaders something like:
GET / HTTP/1.1 User-Agent: Mozilla/5.0 ... deleted ... Referer: http://clanmills/ Accept: */* Accept-Language: en-us Accept-Encoding: gzip, deflate Connection: keep-alive Host: clanmills:80
The HTTP Server is able to use the Host: request to apply the request to /Users/rmills/clanmills. Ingenious, isn't it?
1 Virtual Hosts - Apache (2.2.6) on MacOS-X 10.5
You have to change two files:
In the file /etc/achache2/httpd.conf, you'll have to uncomment the line 468:
# Virtual hosts Include /private/etc/apache2/extra/httpd-vhosts.conf
This in consequence causes /etc/apache2/extra/httpd-vhosts.conf to be read. And I commented off everything in httpd-vhosts.conf and replaced it with:
# # Use name-based virtual hosting. # # NameVirtualHost *:80 # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a ServerName or ServerAlias in any <VirtualHost> block. # #<VirtualHost *:80> # ServerAdmin email@example.com # DocumentRoot "/www/docs/dummy-host.example.com" # ServerName dummy-host.example.com # ServerAlias www.dummy-host.example.com # ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log" # CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log common" #</VirtualHost> # #<VirtualHost *:80> # ServerAdmin firstname.lastname@example.org # DocumentRoot "/www/docs/dummy-host2.example.com" # ServerName dummy-host2.example.com # ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log" # CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log common" #</VirtualHost> # ------------------------------- # rmills Added clanmills virtual host 09.06.07 # NameVirtualHost * <VirtualHost *> ServerName localhost DocumentRoot /Library/WebServer/Documents </VirtualHost> <VirtualHost *> ServerName clanmills DocumentRoot /Users/rmills/clanmills Options FollowSymLinks MultiViews Includes DirectoryIndex index.html default.shtml AccessFileName .htaccess <Files *> Options +Includes </Files> <Directory *> AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost *> ServerName striders DocumentRoot /Users/rmills/Striders Options FollowSymLinks MultiViews Includes DirectoryIndex index.html default.shtml AccessFileName .htaccess <Files *> Options +Includes </Files> <Directory *> AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost *> ServerName heather DocumentRoot /Users/rmills/heather/httpdocs Options FollowSymLinks MultiViews Includes DirectoryIndex index.html default.shtml AccessFileName .htaccess <Files *> Options +Includes </Files> <Directory *> AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>
The effect of all of this is:
2 Virtual Hosts - Apache (1.3.33) on MacOS-X 10.4
I was able to put all the changes into /etc/httpd/httpd.conf. Look for (around line 1080) the statement:
And replace it with a block of <VirtualHost> code similar to the Apache 2.2 code.
3 Virtual Hosts - Apache on Windowshttp://www.imagevertex.com/rmills/
I haven't needed to do this. However, I believe you can do something very similar to the MacOS-X procedures above - depending on whether you have Apache 1.x or 2.x installed on your machine. I have listed a couple of URLs at the top of this article which deal with Windows.
4 Virtual Hosts - IIS on Windows XP
I've never discovered how to do this. If you know, please email and I'll be happy to update this article and acknowledge your help.
I maintain two web sites on my windows machine. I have clanmills.com in the directory c:\web\clanmills and stevenscreekstriders.org in c:\web\striders. So I keep a shortcut on my desktop to open the IIS Control Panel. I created this by opening the control panel/Administrative Tools. You'll find an icon for "Internet Information Services" there. I alt-dragged (copied) the icon to the desktop. The "Magic" is to set the shortcut target = "%SystemRoot%\System32\inetsrv\iis.msc"
So when I want to change from one host to another, I open the IIS Control Panel and drill down to Web Sites/Web site/Properties/Home directory and set Local Path. I know this is really dumb and tedious - however it works!
I'm very happy to accept comments, feedback and suggestions for any of my articles. I'm always happy to hear you - especially if you have constructive suggestions. And I'm particularily pleased if you can let me know about corrections.