Reputation: 125835
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?
Upvotes: 0
Views: 804
Reputation: 1388
Answer of the cPanel/WHM support of 2022 :
Bref, there is a feature in the management interface at :
WHM / Service Configuration / Apache Configuration / Include Editor / Pre VirtualHost Include
where you can put your <VirtualHost 1.2.3.4:80 and 443
Upvotes: 0
Reputation: 125835
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.
Upvotes: 0
Reputation: 311
We currently use scheme where we first include specific default VHost config file, like so (that is before any VHost definitions):
Include conf.d/vhost.d/default.conf.first
Include conf.d/vhost.d/*.conf
This way VHost defined in conf.d/vhost.d/default.conf.first
is always first.
Upvotes: 0
Reputation: 471
Create an .htaccess that proxies all requests back to localhost but on an internal port. Then add a Listen directive for the new port and a VirtualHost for that port that is the default you want.
I should mention that this is ugly, but I think it satisfies your needs.
Upvotes: 0
Reputation: 452
A bit old school I know, but url masking using a frame on your default page could be the easiest thing to do here?
Upvotes: 0
Reputation: 2008
In general VirtualHost
s matches the DNS entries, including wildcards.
Your situation seems to me like you are activating a new site and while the DNS is ready, the hosting isn't available yet, so you want to temporary display a specific VirtualHost
.
I've had a similar problem in the past, and solved it by creating an .htaccess
inside the default VirtualHost
that redirects to the site I want.
This also has the benefit that the user is clearly viewing the real hostname in his browser.
I know that this isn't the solution you wanted, however I don't think there is any other way to accomplish this, because this has limited applications in normal usage (unusual behaviour).
Upvotes: 1