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

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias *.example.com

    . . .

</VirtualHost>

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

<VirtualHost *:80>
    ServerName staging.example.com
    ServerAlias *.staging.example.com

    . . .

</VirtualHost>

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

[ad#Google Adsense 728×90]

Share