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:
*:80>
ServerName
www.example.com
*:80>
ServerName example.com
ServerAlias
*.example.com
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?
Thanks!
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:
*:80>
ServerName
example.com
*:80>
ServerName
www.example.com
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.
Answer
Update: * is valid syntax but not necessary.
You can find out more href="http://httpd.apache.org/docs/2.0/mod/core.html#servername" rel="nofollow
noreferrer">here.
This will work
though.
*:80>
ServerName
example.com
*:80>
ServerName
www.example.com
The
first directive will match everything that is not explicitly defined
elsewhere.
Comments
Post a Comment