[Howto] cPanel default page on direct IP access

Taking care of cPanel hosting servers brought up a problem. Every time someone would type in the browser one of the server’s IP’s directly (except the main IP), the first domain registered on that IP would show up. Have you ever tried this on your server? You can imagine how that could be a problem when the owner of a site for a retirement home for example, would put in his IP and get a nude photographer’s website on his screen. If a domain does not have a wildcard subdomain added to it, if you mistyped a subdomain you would get again the nude photographer’s page. And that’s not cool, is it?

I’ve been looking around, searching and when I didn’t get any results to my queries I went the other way around and started poking with the templates used to generate the apache configuration files. The solution showed up pretty fast, the tests on the test machine went well, and we started deployment of the tweak to the production servers.

Basically, what you need to do is find the file: /var/cpanel/templates/apache2/main.default, back it up somewhere safe, then edit the original.

Look for the lines containing:

[%- FOREACH nvh IN namevirtualhosts -%]
NameVirtualHost [% nvh %]

place a comment in the file just below “NameVirtualHost” using # signs, something like:
### default cPanel page tweak
This will be visible as a comment later in your httpd.conf file.

Now look below for the first  VirtualHost definition block it looks like this on my x86_64 test machine:


ServerName [% servername %]
DocumentRoot [% serverroot %]/htdocs
ServerAdmin [% serveradmin %]
[%- IF supported.mod_suphp %]

suPHP_UserGroup nobody nobody

[%- END %]
[%- IF supported.mod_userdir && userdirprotect_enabled && defaultvhost.userdirprotect != '-1' %]
UserDir disable
[%- IF defaultvhost.userdirprotect != '' %]
UserDir enabled [% defaultvhost.userdirprotect %]
[%- END -%]
[%- END %]

and like this on my i386 test machine:


ServerName [% servername %]
DocumentRoot [% serverroot %]/htdocs
ServerAdmin [% serveradmin %]
[%- IF supported.mod_suphp %]

suPHP_UserGroup nobody nobody

[%- END %]
[%- IF supported.mod_userdir && userdirprotect_enabled && defaultvhost.userdirprotect != '-1' %]
UserDir disable
[%- IF defaultvhost.userdirprotect != '' %]
UserDir enabled [% defaultvhost.userdirprotect %]
[%- END -%]
[%- END %]

Make sure you know what architecture your server is running on if you are going to use the code on this page, but I suggest you use the code already in the file.

Copy the VirtualHost definition block just under the comment you added before, and change the [% vh %] to [% nvh %] on the first line of the VirtualHost definition block just like the NameVirtualHost parameter.

You can add a new line of # symbols under the text you pasted in the file, to have it stand out in the config file, and you should be about done with this file.

Back up your httpd.conf file located in /etc/httpd/conf/httpd.conf then run the following command:
/scripts/rebuildhttpdconf ; /etc/init.d/httpd restart

This will rebuild your httpd.conf, and then restart your apache server, with your brand new default cPanel webpage on all the server’s IP’s.