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 am trying to have all subdomains point to one location on disk, and a particular subdomain (dev) point to another.

I tried this :

<VirtualHost cueflash.com>
 ServerAdmin webmaster@localhost
 ServerAlias www.cueflash.com *.cueflash.com
 DocumentRoot /home/cueflash/www/cueflash.com
 CustomLog /var/log/apache2/cueflash.com.log combined
 ErrorLog /var/log/apache2/cueflash.com.error.log
</VirtualHost>

<VirtualHost dev.cueflash.com>
 ServerAdmin webmaster@localhost
 ServerAlias dev.cueflash.com
 DocumentRoot /home/cueflash/www/dev.cueflash.com
 CustomLog /var/log/apache2/cueflash.com.dev.log combined
 ErrorLog /var/log/apache2/cueflash.com.error.dev.log
</VirtualHost>

But both seem to point to the main site.

share|improve this question
add comment

3 Answers 3

Wildcard "capture" happens on a first-come, first-served basis in Apache. Try swapping the order of those vhosts around, so that the dev site is first in the list.

share|improve this answer
add comment

I'm a little confused. It looks like both hostnames you've used above (dev.cueflash.com and cueflash.com) resolve to the same IP address, which suggests you're trying to use name based virtual hosting...but neither of your VirtualHost blocks includes a ServerName directive (and the arguments to the VirtualHost block are arguably incorrect for named based virtual hosting). I'm not sure what the behavior of ServerAlias is without a corresponding ServerName.

You will also need to verify that you have an appopriate NameVirtualHost directive in your configuration. As specified in the documentation, if you are using name-based virtual hosts, the argument to the opening container should match exactly the argument to the NameVirtualHost directive. For example:

  NameVirtualHost *:80

  <VirtualHost *:80>
    ServerName cueflash.com
    ...
  </VirtualHost>

Maybe you want to take a look at the documentation regarding name-based virtual host support for Apache.

For hostnames that don't explicitly match a ServerName or ServerAlias directive, you get the "default virtual host", which is "whichever virtual host Apache finds first in your configuration". I suspect this, in combination with your other problems, is why everything is hitting the main site.

share|improve this answer
add comment
up vote 0 down vote accepted

Ok, figured out how to do it. Basically, you do all of the non-wildcard hosts first, and then do the wildcard seperately since it follows a first precedence order (the first successful match is the one that is used).

<VirtualHost *>
 ServerName cueflash.com
 ServerAlias www.cueflash.com cueflash.com
 ServerAdmin webmaster@localhost
 DocumentRoot /home/cueflash/www/cueflash.com
</VirtualHost>

<VirtualHost *>
 ServerName dev.cueflash.com
 ServerAdmin webmaster@localhost
 DocumentRoot /home/cueflash/www/dev.cueflash.com
</VirtualHost>

<VirtualHost *>
 ServerName *.cueflash.com
 ServerAdmin webmaster@localhost
 DocumentRoot /home/cueflash/www/cueflash.com
</VirtualHost>

You could set

<VirtualHost *> 

to

<VirtualHost *:80> 

depending on your listener. Also, not that I didn't include various settings for things like error logs. You will need them on each of your VirtualHost listings

share|improve this answer
1  
Wildcard hostnames (*.example.com) are only possible with the ServerAlias but not with the ServerName directive. You've also written cueflash.com in ServerName and ServerAlias which is basically invalid (but works anyway). –  joschi Jan 13 '10 at 17:12
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.