Apache 2 Only Serves First Virtual Host

Note: this post is mainly to help people searching for a solution to this issue.

Yesterday I upgraded to Mac OS X 10.5 Leopard which brought Apache 2 to me along with the many other changes. I develop sites locally using domains like alexking.dev, crowdfavorite.dev, etc. by setting these up HOSTS entries and virtual hosts in Apache.

In Apache 1.x, I had the following in my httpd.conf:

NameVirtualHost *:80

<VirtualHost *>
DocumentRoot /path/to/site
ServerName alexking.dev
</VirtualHost>
...

This worked fine, serving all of my virtual hosts.

After Leopard upgraded me to Apache 2, I added this to my /etc/apache2/extra/httpd-vhosts.conf file and enabled that file in the httpd.conf file. After doing so, no matter which site I tried to load (alexking.dev, crowdfavorite.dev, etc.), it would only load the first declared virtual host.

My Apache skills are feeble, but luckily, our resident Crowd Favorite Linux jockey came to my rescue. Mike knew that Apache 2 handled the *:80 differently than Apache 1.x. Sure enough, this simple change:

NameVirtualHost *

<VirtualHost *>
DocumentRoot /path/to/site
ServerName alexking.dev
</VirtualHost>
...

and everything worked like a champ.

Hopefully this will help someone else struggling with the same issue.