Today, in order to make some testing easier, I wanted to setup a named virtual host in Apache. Here’s how I did it.
In terminal,
mate /etc/hosts # open hosts file in textmate
Add this line:
127.0.0.1 www.layersix.dev
This tells your browser (or whatever) to look on your personal webserver for any requests to www.layersix.dev. In terminal, do
lookupd -flushcache
to make sure you clear your cache of dns names.
In terminal,
mate /etc/httpd/httpd.conf
This is the apache settings file. Look for “NameVirtualHost” and make sure the line reads
NameVirtualHost *:80
Make sure there is no # before this.
Add the following:
<virtualhost *:80=""> DocumentRoot /Library/WebServer/Documents/layersix.dev ServerName www.layersix.dev </virtualhost>
Go to /Library/WebServer/Documents/ and make a folder called layersix.dev (or whatever). Make a file called index.html and put some text in it. I did echo ‘hi’ > layersix.dev/index.html. Restart your webserver in System Preferences > Sharing. Go to www.layersix.dev in Firefox or whatever browser you use. You should now see your index.html file.
This post was helpful in figuring this out:
http://www.macosxhints.com/article.php?story=20010423075959611