As documented by Apache under Using Name-based Virtual Hosts:
If no matching virtual host is found, then the first listed virtual host that matches the IP address will be used.
As a consequence, the first listed virtual host is the default virtual host.
Currently, the template at /var/cpanel/templates/apache2_4/main.default
generates such a default VirtualHost (per IP address) with DocumentRoot [% serverroot %]/htdocs
.
We would instead like the VirtualHost
that is generated for a particular user to be that default. What is the best/recommended way of accomplishing this?
My current thinking is to place the user's (compiled) VirtualHost
directive in /usr/local/apache/conf/includes/pre_virtualhost_2.conf
, but this obviously won't be managed by WHM should the user's configuration change.
Is there a better way?
Okay, so this is what I ended up doing:
Copied /var/cpanel/templates/apache2_4/main.default
to /var/cpanel/templates/apache2_4/main.local
.
Edited the newly created copy to remove the default VirtualHost
directives (I inserted [%- IF 0 %]
before line 344 and [% END -%]
before line 385).
Edited /var/cpanel/conf/apache/primary_virtual_hosts.conf
so that the name of the desired default host was specified for the desired IP address(es).
Ran /scripts/rebuildhttpdconf
.
Manually verified /usr/local/apache/conf/httpd.conf
.
Gracefully restarted Apache.