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!

WHM Virtualhost not working

Discussion in 'Bind/DNS/Nameserver' started by mmilo, Nov 13, 2014.

  1. mmilo

    mmilo Registered

    Joined:
    Aug 1, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hi,

    I have a brand new WHM 11.46.0 (build 12) on a VPS. I only have a single IP on the VPS
    My hostname is server.domain.com

    I'm trying to get a subdomain working with a virtualhost, so that www.domain.com and sub.domain.com have different DocumentRoots.

    Now, WHM autogenerated the following in httpd.conf:

    Code:
    NameVirtualHost 127.0.0.1:80
    NameVirtualHost *
    

    I added the following to the "Post VirtualHost" include file:
    Code:
    <VirtualHost *>
            ServerName www.domain.com
            ServerAlias www.domain.com
            DocumentRoot "/usr/local/apache/htdocs/main" 
    </VirtualHost>
    <VirtualHost *>
      ServerName sub.domain.com
      ServerAlias sub.domain.com
      DocumentRoot "/usr/local/apache/htdocs/subdomain" 
    </VirtualHost>
    
    In this case, the default /usr/local/apache/htdocs/index.html page is loaded - the auto-generated Virtualhost for WHM.

    If I put this in the "Pre VirtualHost" include file instead, it makes no difference.

    Now if I use the following...

    Code:
    <VirtualHost 107.182.162.15:80 127.0.0.1:80>
    
    Then due to precedence/usr/local/apache/htdocs/main is loaded. However, the subdomain is never recognized.

    When I run httpd -S I get the following:
    Code:
    107.182.162.15:80      www.domain.com (/usr/local/apache/conf/includes/pre_virtualhost_2.conf:1)
    107.182.162.15:443     server.domain.com (/usr/local/apache/conf/httpd.conf:319)
    127.0.0.1:80           is a NameVirtualHost
             default server www.domain.com (/usr/local/apache/conf/includes/pre_virtualhost_2.conf:1)
             port 80 namevhost www.domain.com (/usr/local/apache/conf/includes/pre_virtualhost_2.conf:1)
             port 80 namevhost sub.domain.com (/usr/local/apache/conf/includes/pre_virtualhost_2.conf:8)
             port 80 namevhost server.domain.com (/usr/local/apache/conf/httpd.conf:282)
    127.0.0.1:443          server.domain.com (/usr/local/apache/conf/httpd.conf:319)
    wildcard NameVirtualHosts and _default_ servers:
    *:*                    is a NameVirtualHost
             default server www.domain.com (/usr/local/apache/conf/includes/pre_virtualhost_2.conf:1)
             port * namevhost www.domain.com (/usr/local/apache/conf/includes/pre_virtualhost_2.conf:1)
             port * namevhost sub.domain.com (/usr/local/apache/conf/includes/pre_virtualhost_2.conf:8)
             port * namevhost server.domain.com (/usr/local/apache/conf/httpd.conf:263)
    
    (server.domain.com is my WHM hostname)

    How can I fix this?

    Thank you!
     
  2. mmilo

    mmilo Registered

    Joined:
    Aug 1, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Welp, looks like I had to edit /var/cpanel/templates/apache2/main.local , and changed

    Code:
    [%- FOREACH nvh IN namevirtualhosts -%]
    NameVirtualHost [% nvh %]
    [% END -%]
    NameVirtualHost *
    
    to

    Code:
    [%- FOREACH nvh IN namevirtualhosts -%]
    NameVirtualHost [% nvh %]
    [% END -%]
    NameVirtualHost myip:80
    
     
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