Take the 2-minute tour ×
Server Fault is a question and answer site for professional 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:

NameVirtualHost 10.10.0.205

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

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

A hostname such as www.domain.com.dev, correctly resolves to 10.10.0.205, 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):

10.10.0.205:*          is a NameVirtualHost
    default server *.test
    port * namevhost *.test
    port * namevhost *.dev
share|improve this question
add comment

1 Answer

up vote 7 down vote accepted

Use ServerAlias, rather than ServerName alone:

ServerName somename.dev

ServerAlias *.dev

share|improve this answer
    
Thanks for the quick response. Works like a charm! –  Martijn Heemels May 7 '10 at 15:50
add comment

Your Answer

 
discard

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.