Promote particular user's Apache VirtualHost to default
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?
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?
-
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? 0 -
Yes, you could simply manually modify the position of the VirtualHost in /usr/local/apache/conf/httpd.conf and distill the changes via: /usr/local/cpanel/bin/apache_conf_distiller --update
Thank you.0 -
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. ServerName domain.com ServerAlias *.domain.com www.domain.com etc... ServerName blog.domain.com ServerAlias www.blog.domain.com etc... ServerName blog2.domain.com ServerAlias www.blog2.domain.com
etc...0
Please sign in to leave a comment.
Comments
7 comments