Apache Web-Serving with Mac OS X, Part 6
Subject:   How to setup virtual hosts
Date:   2002-10-10 22:24:36
From:   kiddailey
Response to: what about Virtual Hosts?


I grew impatient and figured out a way to do this myself -- it was extremely easier than I thought it would be. Standard disclaimer applies: it worked for me, but I take no responsibility :)

Step 1:

Load up your http.conf file (/etc/httpd/httpd.conf) in your favorite text editor, and uncomment the following lines by removing the pound sign (#):

#LoadModule vhost_alias_module libexec/httpd/

#AddModule mod_vhost_alias.c

Step 2:

Search for the following line:

UseCanonicalName On

... and turn it off by changing it to:

UseCanonicalName Off

Step 3:
Add the following line right below the last one you modified in step 2:

VirtualDocumentRoot /Library/WebServer/Documents/%0

Basically this says reroute to the folder that matches the server name. i.e. -> /Library/WebServer/Documents/ In theory, you could use any folder, but I chose to simply repurpose my webserver documents directory.

Step 4:
Save the file and restart your web server (turn web sharing off and then on again).

Now the trick to getting this to work completely is to simply create folders for each domain name you want to host virtually. For example, say you have two sites: and In your webserver documents folder, you'd simply create folders with the same names:


And put the files for each site in the respective folders.


Note that you might need to tweak this to get and to point to the same place (using aliasing, I'd imagine). You can read all about the vhost_alias module and VirtualDocumentRoot directive at

1 to 1 of 1
  1. How to setup virtual hosts
    2007-03-08 11:23:01 [View]

1 to 1 of 1