Revision of Enabling Dynamically Configured Name-based Virtual Hosting on Mac OS X from April 9, 2004 - 12:40am

Enabling virtual hosting on your Mac OS X machine will allow you to serve web content from a single IP address for multiple domain names, including sub-domains.

Apart from the virtual hosting setup, you will need to separately have a DNS entry that points to your machine. For testing, I recommend using the "fake" method described in the evolt article at the end of this document.

Alternately, you can setup dynamic DNS using either a free provider or EasyDNS, where you can get a "real" domain name and manage your DNS.

All the following involves editing your httpd.conf file, which requires admin privileges. It is located at /etc/httpd/httpd.conf, and it's best to make a backup before you begin.

First, you need to uncomment this section:

#LoadModule vhost_alias_module libexec/httpd/mod_vhost_alias.so

Uncomment this one too:

#AddModule mod_vhost_alias.c

Decide where you want to put all your web files. I placed them all in a directory next to the main, default server, at /Library/WebServer/Hosts. Create that directory.

Now add this snippet at the end of the file:

VirtualDocumentRoot /Library/WebServer/Hosts/%0/Documents
VirtualScriptAlias /Library/WebServer/Hosts/%0/CGI-Executables

Now restart your web server.

apachectl graceful

If you don't see any errors, everything should be working.

At this point, you should be able to add folders like /Library/WebServer/Hosts/example.bmannconsulting.com/Documents and you're good to go. You can also use symlinks, so have multiple domains point to the same content. Any domains or the raw IP address will go to your default, which is still at /Library/WebServer/Documents.

Related Links