Carl Tashian

« Incompetence | Main | The Silver Seas »

Nov 30 02007 1.18p

I’m posting this only because I had trouble getting Apache back into shape after a Leopard upgrade, and I wanted to post a fix. Switching to Leopard (which comes with Apache 2.2), I needed to get virtual hosting working again for my development work. Some files and settings have moved.

The apache config for Leopard is in /etc/apache2/httpd.conf, and to turn on virtual hosting you must uncomment line 461, which includes /private/etc/apache2/extra/httpd-vhosts.conf. While you’re at it, if you need PHP, uncomment line 114.

Then edit httpd-vhosts.conf. I wanted to still be able to use the Mac’s default DocumentRoot for requests on localhost, but turning on virtual hosting in Apache 2.2 disables the server-wide DocumentRoot and ServerName, and the first virtual host you define becomes the default instead. Here’s what I needed in order to get my specific name-based virual hosts working:

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
  DocumentRoot "/Library/WebServer/Documents"
</VirtualHost>

<VirtualHost *:80>
  ServerName myrailsapp.biz
  ProxyPass / http://127.0.0.1:3000/  
</VirtualHost>

<VirtualHost *:80>
  ServerName wpclient.com
  DocumentRoot "/Library/WebServer/Documents/wpclient.com"
</VirtualHost>

This configuration should work for multiple virtual hosts, but for me it wasn’t totally successful until after restarting the system—a simple “sudo apachectl graceful” didn’t do the trick. It may be that I also modified /etc/hosts and the system wasn’t fully assimilating my changes. Also, since I had upgraded from Tiger, my user-specific configuration files had moved, so my userdir (http://localhost/~carl/) stopped working! The fix for this was:

sudo cp /etc/httpd/users/* /etc/apache2/users/

Leave a comment

(required)

(required)