Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Custom VirtualHosts

Discussion in 'EasyApache' started by Senor, Mar 8, 2019.

  1. Senor

    Senor Active Member

    Joined:
    Jun 12, 2007
    Messages:
    40
    Likes Received:
    2
    Trophy Points:
    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.
     
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    47,331
    Likes Received:
    2,161
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Senor

    Senor Active Member

    Joined:
    Jun 12, 2007
    Messages:
    40
    Likes Received:
    2
    Trophy Points:
    58
    cPanel Access Level:
    Root Administrator
    That sort of did it.

    Accessing via IP (http://1.2.3.4) still showed the default cPanel webpage (from multiple computers -- not a cache issue).

    Accessing via IP with a path appended (http://1.2.3.4/path/to/whatever) showed the correct website.

    Not sure what I'm missing.

    Thanks for all the help!
     
  4. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    47,331
    Likes Received:
    2,161
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello @Senor,

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

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. Senor

    Senor Active Member

    Joined:
    Jun 12, 2007
    Messages:
    40
    Likes Received:
    2
    Trophy Points:
    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 me@foo.bar
      <IfModule mod_suphp.c>
        suPHP_UserGroup nobody nobody
      </IfModule>
     </VirtualHost>
    
     
  6. Senor

    Senor Active Member

    Joined:
    Jun 12, 2007
    Messages:
    40
    Likes Received:
    2
    Trophy Points:
    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?
     
  7. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    47,331
    Likes Received:
    2,161
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Try setting this to "/home/user/public_html/".

    The entry should utilize the internal IP address (assuming you've setup 1:1 NAT on this server).

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  8. Senor

    Senor Active Member

    Joined:
    Jun 12, 2007
    Messages:
    40
    Likes Received:
    2
    Trophy Points:
    58
    cPanel Access Level:
    Root Administrator
    Awesome, that did it.

    Thanks for all the help!
     
  9. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    47,331
    Likes Received:
    2,161
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    I'm glad to see that worked. Thanks for sharing the outcome!

    I've marked this thread as solved.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  10. Senor

    Senor Active Member

    Joined:
    Jun 12, 2007
    Messages:
    40
    Likes Received:
    2
    Trophy Points:
    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?
     
  11. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    47,331
    Likes Received:
    2,161
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  12. Senor

    Senor Active Member

    Joined:
    Jun 12, 2007
    Messages:
    40
    Likes Received:
    2
    Trophy Points:
    58
    cPanel Access Level:
    Root Administrator
    @cPanelMichael

    I've disabled that feature and will update if the issue happens again.

    Thanks again for all your help.
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice