Minority Opinions

Not everyone can be mainstream, after all.

Virtual Apache

leave a comment »

I feel foolish.

I spent far too long setting up a virtual host on a new Apache server.  I’ve maintained such a system before, so it shouldn’t be a problem, right?  But my new site file simply wasn’t working:

<VirtualHost test.example.com:80>
    ServerAdmin webmaster@test.example.com
    DocumentRoot /srv/http/test.example.com
    <Directory /srv/http/test.example.com>
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

Apache was still serving the default site, even after reloading the config.  I removed periods from the filenames, reloaded, switched the order of the filenames, reloaded; nothing was helping.  Finally, I looked up the VirtualHost documentation.

One glance, and I had my answer.  The VirtualHost parameter wants an IP address, not a host name.  The host name goes in a ServerName parameter.  I’ve used that parameter before, as well as ServerAlias lines with over a dozen names, but the star in the default site file became an obvious place to edit.

Granted, I didn’t spend nearly as much time on that slip-up as I once did on convincing Apache to serve multiple virtual hosts over SSL.  Fortunately, each host had at least one alias for a subdomain covered by our wildcard certificate, so I didn’t need to rely on SNI from the client.  Unfortunately, my first, second, and third attempts all missed a crucial line:

NameVirtualHost *:443

Yes, Apache needs to be told to use virtual hosts on the SSL port, even though its stock configuration does so for port 80.  Even with that, there’s some annoying duplicate configuration for :80 and :443 ports per virtual host, but everything works fine.

Advertisements

Written by eswald

25 Jun 2013 at 7:41 pm

Posted in Technology

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s