ServerName wildcards in Apache name-based virtual hosts?
Posted
by Martijn Heemels
on Server Fault
See other posts from Server Fault
or by Martijn Heemels
Published on 2010-05-07T15:30:49Z
Indexed on
2010/05/07
15:38 UTC
Read the original article
Hit count: 349
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
© Server Fault or respective owner