Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

On our LAN I've set up several 'fake' TLDs in the DNS server, with the intention of using them for Apache name-based virtual hosting. I'd like to combine this with mass-virtual-hosting (i.e. VirtualDocumentRoot) on an Ubuntu 10.04 LAMP server.

However, I can't get it to select the right vhost!

Here is a summary of the Apache config:


   ServerName *.test
   VirtualDocumentRoot /var/www/%-3.0.%-2/test/%1/
   CustomLog /var/log/apache2/access.log vhost_combined

   ServerName *.dev
   VirtualDocumentRoot /var/www/%-3.0.%-2/dev/%1/
   CustomLog /var/log/apache2/access.log vhost_combined

A hostname such as, correctly resolves to, but always selects the top vhost, instead of the bottom one, which matches more closely.

I was under the impression that Apache would first try to match the ServerName before defaulting to the top vhost for a given IP. What am I doing wrong? Or is this not possible and must I use another IP for each TLD?

apachectl -S outputs (trimmed):*          is a NameVirtualHost
    default server *.test
    port * namevhost *.test
    port * namevhost *.dev
share|improve this question

1 Answer 1

up vote 12 down vote accepted

Use ServerAlias, rather than ServerName alone:


ServerAlias *.dev

share|improve this answer
Thanks for the quick response. Works like a charm! – Martijn Heemels May 7 '10 at 15:50
Recent apache versions will no longer even allow wildcards in ServerName, and the error tells you to use ServerAlias instead. – kkhugs Oct 1 at 18:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.