Be careful naming Apache virtual host files

I came across a stupid problem the other day while trying to figure out why my site changes weren’t showing up.

I’m writing my problem and solution on my blog so I’ll remember and not screw up the same way again.

Consider the following virtual host files.

/etc/apache2/sites-available/example.com-05-production.vhost


    ServerName www.example.com
    ServerAlias *.example.com

    . . .

/etc/apache2/sites-available/example.com-10-staging.vhost


    ServerName staging.example.com
    ServerAlias *.staging.example.com

    . . .

My goal is to have www.example.com and anything.example.com point to one vhost with the exception of staging.example.com and anything.staging.example.com. The problem is that Apache loads the scripts in order by file name. So when the second virtual host is loaded Apache pretty much ignores it because *.example.com overrides staging.example.com.

I changed my file names of my vhost files, reloaded Apache, and all was fixed.

The correct file names:
/etc/apache2/sites-available/example.com-05-staging.vhost
/etc/apache2/sites-available/example.com-10-production.vhost

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.