Default vhost for dedicated IP address

omnicognate

Registered
Nov 5, 2011
2
0
51
cPanel Access Level
Root Administrator
Seems many of the questions here are about default vhosts, but I have looked and am unable to find an answer for this one. The following similar questions didn't get any answers:

http://forums.cpanel.net/f5/dedicat...-74161.html?highlight=default+vhost+dedicated
http://forums.cpanel.net/f5/make-ap...208952.html?highlight=default+vhost+dedicated

On my server, to which I have root access, I have assigned a dedicated IP address to a couple of subdomains by following the instructions at Assigning Dedicated IPs to Subdomains.

This is working fine, but unlike my main shared IP address, which defaults to the default vhost template when accessed through anything other than the configured domain names, I've noticed that the dedicated IP defaults to the the vhost of one of the two subdomains I've assigned to it. (It was a bit of a shock to discover that some random 3rd party dns entry that happened to be set to the same IP address had started showing up in google with my website contents :eek:)

Is there any way to set the default vhost for a dedicated IP address? A way that uses the cpanel config files rather than editing the generated httpd.conf would obviously be preferable, but if httpd.conf has to be edited, what's the best way to do it?
 

omnicognate

Registered
Nov 5, 2011
2
0
51
cPanel Access Level
Root Administrator
Sorted it out. Posting here in case anybody else has the same problem.

I copied /var/cpanel/templates/apache2/main.default to /var/cpanel/templates/apache2/main.local and edited the new copy, main.local.

I found the following lines.

Code:
[%- FOREACH nvh IN namevirtualhosts -%]
NameVirtualHost [% nvh %]
[% END -%]
NameVirtualHost *
After these lines, I added the following, replacing myip with the dedicated IP address and /some/folder with a nonexistent folder (as I want a 404 if anyone access the site other than through the proper domain name):

Code:
<VirtualHost myip:80>
  DocumentRoot /some/folder
</VirtualHost>
I then ran the following commands to rebuild the apache config and restart the server.

Code:
[B]/usr/local/cpanel/scripts/rebuildhttpdconf
[B]/usr/local/cpanel/scripts/restartsrv_apache[/B][/B]
Seems to work, though it seems a shame to have to copy the main template to do something so simple. Perhaps someone knows a better way...?