Here is my current setup:
At the bottom of httpd.conf
I have the following:
NameVirtualHost *:80
Include /etc/httpd/conf/vhosts/*
Inside of /etc/httpd/conf/vhosts
I have the following files:
mainsite.com.conf:
<VirtualHost *:80>
DocumentRoot "/var/www/vhosts/mainsite.com"
ServerName mainsite.com
ServerAlias www.mainsite.com
<Directory "/var/www/vhosts/mainsite.com">
allow from all
Options -Indexes
</Directory>
</VirtualHost>
sub1.mainsite.com.conf:
<VirtualHost *:80>
DocumentRoot /var/www/vhosts/sub1.mainsite.com
ServerName sub1.mainsite.com
<Directory "/var/www/vhosts/sub1.mainsite.com">
allow from all
Options -Indexes
</Directory>
</VirtualHost>
So far so good! mainsite.com
and www.mainsite.com
both share the same DocumentRoot
(and with some redirection later I can redirect all www.mainsite.com
users to mainsite.com
for SEO). sub1.mainsite.com
also has its own DocumentRoot
and doesn't interfere with anything else.
However, <Anything that isn't www or sub1>.mainsite.com
gets the same DocumentRoot
that mainsite.com
and www.mainsite.com
get. What I would prefer instead is an error page to come up for any host that doesn't match a VirtualHost
.
And now for the actual question:
What can I tweak to get the desired effect? Also, can the directory rules that are common between the VirtualHost
s be refactored up into httpd.conf
? If so, would I just do something like the following?
<Directory "/var/www/vhosts">
allow from all
Options -Indexes
</Directory>