Apache2 default vhost in alphabetical order or override with _default_ vhost?
- by benbradley
I've got multiple named vhosts on an Apache web server (CentOS 5, Apache 2.2.3).
Each vhost has their own config file in /etc/httpd/vhosts.d and these vhost config files are included from the main httpd conf with... Include vhosts.d/*.conf
Here's an example of one of the vhost confs...
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.domain.biz
ServerAlias domain.biz www.domain.biz
DocumentRoot /var/www/www.domain.biz
<Directory /var/www/www.domain.biz>
Options +FollowSymLinks
Order Allow,Deny
Allow from all
</Directory>
CustomLog /var/log/httpd/www.domain.biz_access.log combined
ErrorLog /var/log/httpd/www.domain.biz_error.log
</VirtualHost>
Now I when anyone tries to access the server directly by using the public IP address, they get the first vhost specified in the aggregated config (so in my case it's alphabetical order from the vhosts.d directory). Anyone accessing the server directly by IP address, I'd like them to just get an 403 or a 404.
I've discovered several ways to set a default/catch-all vhost and some conflicting opinions.
I could create a new vhost conf in vhosts.d called 000aaadefault.conf
or something but that feels a bit nasty.
I could have a <VirtualHost> block in my main httpd.conf before the vhosts.d directory is included.
I could just specify a DocumentRoot in my main httpd.conf
What about specifying a default vhost in httpd.conf with _default_ http://httpd.apache.org/docs/2.2/vhosts/examples.html#default
Would having a <VirtualHost _default_:*> block in my httpd.conf before I Include vhosts.d/*.conf be the best way for a catch-all?