how can I set a default VirtualHost in apache? Preferably, I want the default host not to be the same as the ip address host. Now I have something like this:
If you are using Debian style virtual host configuration (sites-available/sites-enabled), one way to set a Default VirtualHost is to include the specific configuration file first in httpd.conf or apache.conf (or what ever is your main configuration file).
# To set default VirtualHost, include it before anything else.
IncludeOptional sites-enabled/my.site.com.conf
# Load config files in the "/etc/httpd/conf.d" directory, if any.
IncludeOptional conf.d/*.conf
# Load virtual host config files from "/etc/httpd/sites-enabled/".
IncludeOptional sites-enabled/*.conf
The solution is:
NameVirtualHost *:80
Listen 80
(...)
<VirtualHost *:80>
ServerName host1
DocumentRoot /someDir
</VirtualHost>
<VirtualHost *:80>
ServerName host2
DocumentRoot /someOtherDir
</VirtualHost>
<VirtualHost *:80>
ServerName aaaa.com
DocumentRoot /defaultDir
</VirtualHost>
In my case, to work, I created a VirtualHost
(n.e. VirtualHost
per CNAME
) called aaaa.com
since I have different files for different VirtualHost
and knowing that apache2
(n.a. Apache HTTP Server
) reads them in alphabetical order.
NameVirtualHost option would be a good option.