The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Default Vhost

Discussion in 'General Discussion' started by PickMonitor, Oct 11, 2010.

  1. PickMonitor

    PickMonitor Registered

    Joined:
    Sep 22, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    I've searched and found several answers for this, but not one that has worked.

    I'm looking for a solution such that someone can change their nameservers to point to ns1.mydomain.com and ns2.mydomain.com and their site will automatically display the content in the folder "/home/pick/public_html/web_accounts" on my server.

    Because the number of websites who do this nameserver change could be in the thousands, and because each site will be issued the same content, I wish to be able to do this without creating a new account for each site.

    So far everything I have tried leads me to a "Server Not Found" error for the website with the changed nameservers.

    Even when I leave the httpd configuration the way cPanel created it, I still get a "Server Not Found".

    My latest effort was to edit /usr/local/apache/conf/includes/post_virtualhost_2_conf.conf to:


    PHP:
    NameVirtualHost *:80
    <VirtualHost *:80>
    ServerAdmin email_address@pickmonitor.com

    DocumentRoot 
    /home/pick/public_html/web_accounts/
    <
    Directory />
            
    Options FollowSymLinks
            AllowOverride None
    </Directory>
    <
    Directory /home/pick/public_html/web_accounts/>
            
    Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow
    ,deny
            allow from all
    </Directory>
    </
    VirtualHost>
    Any ideas on what I'm doing wrong?
     
  2. Messiah

    Messiah Member
    PartnerNOC

    Joined:
    Jul 5, 2006
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    1
    You've probably got another VirtualHost defined in httpd.conf on *:80 that's overriding this one. You'll have to either make your VirtualHost entry in /usr/local/apache/conf/includes/post_virtualhost_2.conf more specific (ie: 1.2.3.4:80), or define the VirtualHost for *:80 in /usr/local/apache/conf/includes/pre_virtualhost_2.conf.
     
  3. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    The *:80 is the unbound virtual host entry, isn't it? If so, that's only going to be editable in /var/cpanel/templates/apache2/ area for main.default file. To make changes to that file, you'd have to copy it:

    Code:
    cd /var/cpanel/templates/apache2/
    cp main.default main.local
    Then edit main.local file. The section I believe it would be is this one:

    Code:
    # Default vhost for unbound IPs
    <VirtualHost *>    ServerName [% servername %]
        DocumentRoot [% serverroot %]/htdocs
        ServerAdmin [% serveradmin %]
        [%- IF supported.mod_suphp %]
        <IfModule mod_suphp.c>
            suPHP_UserGroup nobody nobody
        </IfModule>
        [%- END %]
        [%- IF supported.mod_userdir && userdirprotect_enabled && defaultvhost.userd
    irprotect != '-1' %]
        UserDir disable    [%- IF defaultvhost.userdirprotect != '' %]
        UserDir enabled [% defaultvhost.userdirprotect %]
        [%- END -%]
        [%- END %]
    </VirtualHost>
    You'd simply have to remove it and hard code what you wanted there. After you changed it, then you'd have to rebuild the Apache configuration and restart Apache to see if the changes worked (I have a backup being made first, please always make a backup before rebuilding / revising anything):

    Code:
    cp /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.bak101011
    /scripts/rebuildhttpdconf
    /etc/init.d/httpd restart
     
  4. PickMonitor

    PickMonitor Registered

    Joined:
    Sep 22, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    That looks great, thanks. Before I try that, let me ask... what is SUPPOSED to happen by default when someone changes their nameservers to point to your server? Am I supposed to get a "server not found" error? or is my server behaving unusually?
     
  5. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Changing to your nameservers is not necessarily telling a domain to use the A record for your machine. The better method would be to have them set their A record to your machine's IP. The nameservers only tell a domain when it has a DNS zone on the nameservers what record to pick up. If your nameservers don't have a DNS zone for the domain, then there's nothing for those nameservers to send back. You will indeed get a server not found if you aren't creating DNS zones for these domains.

    If the domain instead sets your server's IP for the domain's A record, then the domain will come to your server. Because the domain isn't in Apache configuration as an account, it will get handled by the unbound IP virtual host, which is what you are setting up by modifying the template.
     
  6. PickMonitor

    PickMonitor Registered

    Joined:
    Sep 22, 2010
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Thank you soooo much!!!!

    As it turns out, I didn't even need to edit anything in the httpd.conf. I simply created a new account in cPanel with a dedicated IP address, and pointed the A record of each domain to that IP. I can then just use PHP's $_SERVER to output data specific to the url.

    Thanks again.
     
  7. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Great, using a dedicated IP is definitely a good way to go for this configuration you wanted. Glad you found out the best way to accomplish it :)
     
Loading...

Share This Page