I want to map www.example.com to a specific virtual host and then I want all other subdomains of example.com to go to another virtual host.
To do this I created these hosts:
<VirtualHost *:80> ServerName www.example.com </VirtualHost> <VirtualHost *:80> ServerName example.com ServerAlias *.example.com </VirtualHost>
Now the selection of which host is served seems rather random. If I restart apache sometimes I will get one host and other times another.
What am I doing wrong?
Update: If I run apache2ctl -S on this configuration I get this outpu:
VirtualHost configuration: wildcard NameVirtualHosts and _default_ servers: *:80 is a NameVirtualHost default server www.example.com (/etc/apache2/sites-enabled/dev:3) port 80 namevhost www.example.com (/etc/apache2/sites-enabled/dev:3) port 80 namevhost example.com (/etc/apache2/sites-enabled/dev:22)
After much digging around I decided to disable the mono applications that I had running and low and behold it started serving files from the correct site. They did need to be entered in the order:
<VirtualHost *:80> ServerName example.com </VirtualHost> <VirtualHost *:80> ServerName www.example.com </VirtualHost>
as suggested by Wizard. To get my mono apps working I used "MonoAutoApplication enabled" within each virtual host. However I am not sure that this is the best option as on the mono site it says you shouldn't use auto hosting for asp.net mvc apps (which is what I am using). So far I can't see the downside though.