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.

I'm currently looking at the apache documentation regarding virtual host. It gives an example on this page: http://httpd.apache.org/docs/2.0/vhosts/name-based.html

The example they show is:

<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

Wouldn't it work also with this type of config?:

<VirtualHost *:80>
ServerName *.domain.tld
DocumentRoot /www/domain
</VirtualHost>

Or this:

<VirtualHost *:80>
ServerName domain.tld
ServerAlias *.domain.tld
DocumentRoot /www/domain
</VirtualHost>
share|improve this question

2 Answers 2

up vote 0 down vote accepted

You can't use wildcards to specify ServerName as it has to be a FQDN. Your first example with ServerName *.domain.tld will not work as this is not a FQDN. Your second example will work and is quite a common configuration.

One thing to note is that apache processes these directives from top to bottom in the order they are defined and will act upon the first match.

share|improve this answer

Also check your NameVirtualHost directive & documentation [usually in a listen.conf for apache 2.2]

I believe for your vhosts it should be set to:

NameVirtualHost *:80

But double check that, http://httpd.apache.org/docs/2.0/mod/core.html#namevirtualhost

share|improve this answer

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.