Promote particular user's Apache VirtualHost to default

eggyal

Registered
Mar 31, 2015
2
0
1
London, UK
cPanel Access Level
Root Administrator
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?
 

eggyal

Registered
Mar 31, 2015
2
0
1
London, UK
cPanel Access Level
Root Administrator
Thanks cPanelMichael—but following that suggestion appears, to me, to provide little benefit over that I proposed in my question: either way, the arising default VirtualHost configuration will be "detached" from the user's VirtualHost that is managed by WHM.

Is there no way that the "default" vhost can be that of a user, as managed by WHM?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
Yes, you could simply manually modify the position of the VirtualHost in /usr/local/apache/conf/httpd.conf and distill the changes via:

Code:
/usr/local/cpanel/bin/apache_conf_distiller --update
Thank you.
 

terabit

Registered
Aug 14, 2007
2
0
51
I am also trying to reorder the virtualhosts in my httpd.conf but using apache_conf_distiller --update does not seem to preserve their order at all.

My problem is that cpanel keeps rebuilding the config with the wildcard defined first and which makes apache ignore the explicitly named sub domain that is being defined after the wildcard... I need to be able to force cpanel to define multiple virtualhosts before the wildcard host.

Should "apache_conf_distiller --update" be working for this? I don't see any indication in the documentation saying that it would. It seems to only save settings not the order that they are in.

Code:
<VirtualHost xxx.xxx.xxx.xxx:80>
  ServerName domain.com
  ServerAlias *.domain.com www.domain.com
  etc...

<VirtualHost xxx.xxx.xxx.xxx:80>
  ServerName blog.domain.com
  ServerAlias www.blog.domain.com
  etc...

<VirtualHost xxx.xxx.xxx.xxx:80>
  ServerName blog2.domain.com
  ServerAlias www.blog2.domain.com
etc...
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
Thread starter Similar threads Forum Replies Date
Rajesh Chauhan Workarounds and Optimization 1