Senor

Active Member
Jun 12, 2007
40
2
58
cPanel Access Level
Root Administrator
Hi folks -

Forgive me if this has been answered already; I looked and couldn't find an answer.

I know WHM allows you to have custom VirtualHosts and you're supposed to be able to create your own custom include files so nothing gets overwritten when Apache is rebuilt. I am however, struggling with this and would really appreciate some help.

I transferred from one server to another and assume that, when Apache rebuilt for the first time, it screwed up my original config.

Last night at approximately 4AM, my server started serving web requests out of /var/www/html when accessed by its IP. Requests to the sole domain (by name) I have on the box worked just fine.

I realized what the issue was and manually edited httpd.conf, restarted Apache, found some permissions issue which I corrected and was back up and running.

I know this is only temporary and I want to make it permanent, but I've been struggling all day in how to do this properly. I've followed the (hopefully correct) guide but just can't get it to work. All I want is to have requests to the direct IP of my server *not* point to /var/www/html and instead point elsewhere and have it stick.

What is the syntax I need in my include file to overwrite a default VirtualHost?

Thanks in advance.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
Hello @Senor,

You can follow the steps referenced below to control which content appears when navigating directly to an IP address:

1. Navigate to WHM's Include Editor interface (WHM Home >> Service Configuration >> Apache Configuration >> Include Editor).

2. Select the Pre Virtual Host Include option.

3. Select the Apache version from the menu. We recommend that you select All Versions.

4. Enter the following text in the available text box:

Code:
<VirtualHost IPADDRESS:80>
  ServerName HOSTNAME
  DocumentRoot /usr/local/apache/htdocs
  ServerAdmin EMAIL
  <IfModule mod_suphp.c>
    suPHP_UserGroup nobody nobody
  </IfModule>
 </VirtualHost>

<VirtualHost IPADDRESS:443>
  ServerName HOSTNAME
  DocumentRoot /usr/local/apache/htdocs
  ServerAdmin EMAIL
  <IfModule mod_suphp.c>
    suPHP_UserGroup nobody nobody
  </IfModule>
    SSLEngine on
    SSLCertificateFile SSLCERTIFICATEFILE
    SSLCertificateKeyFile YOUR-SSLCERTIFICATEKEYFILE
 </VirtualHost>
Note:

This example uses the following values:
  • IPADDRESS represents your IP address.
  • HOSTNAME represents your server's hostname.
  • EMAIL represents your contact email address.
  • SSLCERTIFICATEFILE represents the full file path to your SSL certificate.
  • SSLCERTIFICATEKEYFILE represents the full file path to your SSL certificate's key.
5. Click Proceed
6. Click Update.

Additionally, note that you'd need to update the DocumentRoot values to reflect the directory associated with the content you want to load.

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
Hello @Senor,

Can you share the specific entry you added? Simply replace real domain names, usernames, and IP addresses with examples.

Thank you.
 

Senor

Active Member
Jun 12, 2007
40
2
58
cPanel Access Level
Root Administrator
Sure. I only did the non-secure (port 80) entry:


Code:
<VirtualHost 1.2.3.4:80>
  ServerName host.domain.com
  DocumentRoot /home/user/www/
  ServerAdmin [email protected]
  <IfModule mod_suphp.c>
    suPHP_UserGroup nobody nobody
  </IfModule>
 </VirtualHost>
 

Senor

Active Member
Jun 12, 2007
40
2
58
cPanel Access Level
Root Administrator
Hmm. If I'm behind a firewall, do I need to have entries for both my internal and external IPs? I only have one for my internal IP. Perhaps that's why it's not working?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
DocumentRoot /home/user/www/
Try setting this to "/home/user/public_html/".

Hmm. If I'm behind a firewall, do I need to have entries for both my internal and external IPs? I only have one for my internal IP. Perhaps that's why it's not working?
The entry should utilize the internal IP address (assuming you've setup 1:1 NAT on this server).

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
Awesome, that did it.

Thanks for all the help!
I'm glad to see that worked. Thanks for sharing the outcome!

I've marked this thread as solved.
 

Senor

Active Member
Jun 12, 2007
40
2
58
cPanel Access Level
Root Administrator
@cPanelMichael

Ok, so while I thought this was solved, twice now in the middle of the night, my server started returning 403 errors when accessing it by its IP. I had to update the permissions of my public_html folder to 0755 for everything to start working again.

It'd be real nice if that stuck so I wasn't woken up at 3 in the morning to make the change.

Accessing by its hostname works without problems (prior to the permissions change, too).

Thoughts?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,880
2,268
463
Hello @Senor,

It's possible the FileProtect feature is conflicting with that manual change. Can you open a support ticket so we can take a closer look to see if that's the case? You can post the ticket number here and we'll update this thread with the outcome.

Thank you.