Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 17 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 '15 at 18:04

If this can help, just to complete a bit Mo's answer:

Wildcards in ServerAlias also works on partial domain names, such as


ServerAlias *

It saved my life recently ^^ (a main site with subdomains for each sub app such as,,

share|improve this answer

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.