Apache Virtual Hosts on OS X Leopard
on Sunday 31st May, 2009 Gabe speculated thusly…If you develop multiple sites and you need virtual hosting functionality, scroll down to the end of the /private/etc/apache2/httpd.conf file and uncomment the following:
# Include /private/etc/apache2/extra/httpd-vhosts.conf
Next, you’ll need to setup whatever virtual hosts you have in the virtual hosts file /private/etc/apache2/extra/httpd-vhosts.conf
You need to make an entry in the httpd-vhosts.conf file like so:
<virtualhost *:80> ServerName beta-site-1.com ServerAlias www.beta-site-1.com ServerAdmin webmaster@beta-site-1.com ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log" CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common DocumentRoot "/Library/WebServer/beta-site-1" ScriptAlias /cgi-bin/ "/Library/WebServer/beta-site-1/cgi-bin"Options FollowSymLinks MultiViews Includes AllowOverride All Order allow,deny Allow from all </virtualhost>
The examples provided by Apple in the vhosts file are slightly incorrect and if you use the CustomLog lines as is you will get errors the following errors if you run: apachectl -t -D DUMP_VHOSTS:
Syntax error on line 40 of /private/etc/apache2/extra/httpd-vhosts.conf:
CustomLog takes two or three arguments, a file name, a custom log format string or format name, and an optional "env=" clause (see docs)
This is because
CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log common
Should actually read:
CustomLog "/private/var/log/apache2/dummy-host.example.com-access_log" common
So one you have a Virtual Host setup how do you get the DNS server on Mac OS X to respond to beta-site-1.com?
You need to enter the domain in to
/etc/hostsfile, like so:127.0.0.1 localhost beta-site-1.comJust put it alongside the line where you have
localhostdefined.