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.

Virtualhost entries gets deleted when apache httpd.conf is rebuilt

Discussion in 'EasyApache' started by amit_roy, Nov 24, 2012.

  1. amit_roy

    amit_roy Member

    Joined:
    Oct 19, 2012
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Background:
    We have been trying to get a wildcard SSL working on multiple sub domains on a single dedicated address. We have two sub domains next.my-personal-website.com and blog.my-personal-website.com

    Part of our strategy has been to edit the httpd.conf and add the NameVirtualHost xx.xx.144.72:443 directive and the virtualhost entries for port 443 for the subdomains there. This works good if we just edit the httpd.conf, add the entries, save it and restart the apache.


    The problem:
    But if we add a new sub domain from cpanel or we run the

    Code:
    # /usr/local/cpanel/bin/apache_conf_distiller --update
    # /scripts/rebuildhttpdconf
    
    the virtualhost entries that we added manually are no more there in the newly generated httpd.conf file. Only the virtualhost entry for the main domain for port 443 that was there before we made edits to the httpd.conf is there(assuming we are not discussing virtualhost entries for port 80).

    I understand we need to put the new virtualhost entries in some include files as mentioned here in the cpanel documentation. But am not sure where to.

    So the question would be where do I put the NameVirtualHost xx.xx.144.72:443 directive and the two virtualhost directive for port 443, so that they are not overwritten when httpd.conf is rebuilt/regenerated later.

    I really appreciate if somebody can help me out on this. Thanks.
     
  2. dalem

    dalem Well-Known Member
    PartnerNOC

    Joined:
    Oct 24, 2003
    Messages:
    2,577
    Likes Received:
    40
    Trophy Points:
    48
    Location:
    SLC
    cPanel Access Level:
    DataCenter Provider
    add it here
    /usr/local/apache/conf/userdata/ssl/2/username/domain,com/includename.conf
     
  3. Bestrafung

    Bestrafung Active Member

    Joined:
    Apr 2, 2012
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
    I don't know if this helps or not but I just completed a Django setup halfway following a guide on these forums. There is a section for setting up the vhost includes. Check out http://forums.cpanel.net/f5/django-python-cpanel-71229-p2.html#post439009, and search for "Set up the vhost". It includes the vhost includes location as well as the scripts to run afterward. Hope that helps.
     
  4. amit_roy

    amit_roy Member

    Joined:
    Oct 19, 2012
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thanks everybody. @Dalem "includename" can be any arbitrary name I assume?Or does it have a specific naming convention?

    Also I wanted to point out I was browsing the posts in this forum and somewhere I found a post where it says the virtualhost entries are stored in YAML format in the /var/cpanel/userdata/USERNAME . I actually went there in our VPS and could see the domain and the subdomain files in YAML format there. But there there was another file for the main domain ending with _SSL my-personal-website.com_SSL . There were no such files(ending with _SSL) for sub domains. Any idea, if I can add it there too.

    I am curious to know are these files generated in the /var/cpanel/userdata/? Are they generated when the httpd.conf is built? or these files are used to generate the httpd.conf?
    Can we manually add an entry for the sub-domain there and then run the

     
  5. Bestrafung

    Bestrafung Active Member

    Joined:
    Apr 2, 2012
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
    If I understand it correctly the include script searches with a wildcard and the "includename" could technically be anything. That said, the default behavior for Apache and other scripts is to look for a "vhost.conf".

    In the post I linked it shows the usage for the scripts to include the vhosts, it generates the full httpd.conf including vhost includes. I only used it for my purposes setting up Django so it may be different for you but the process should be the same when dealing with the includes.

    Example from post:
    nano /usr/local/apache/conf/userdata/std/2/[username]/domain.com/vhost.conf

    /scripts/verify_vhost_includes
    /scripts/ensure_vhost_includes --user=[username]
     
    #5 Bestrafung, Nov 24, 2012
    Last edited: Nov 24, 2012
  6. amit_roy

    amit_roy Member

    Joined:
    Oct 19, 2012
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Thanks @Bestrafung . I will try this out tonight.
     
  7. amit_roy

    amit_roy Member

    Joined:
    Oct 19, 2012
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Tried it. It says

    <VirtualHost> cannot occur within <VirtualHost> section
     
  8. Bestrafung

    Bestrafung Active Member

    Joined:
    Apr 2, 2012
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    6
    cPanel Access Level:
    Root Administrator
    Without seeing your files the obvious guess by that error message is that it looks something like this:
    Code:
    <VirtualHost>
    <VirtualHost>
    </VirtualHost>
    </VirtualHost>
    If using the Django guide as a reference, your include file would look like this:
    Code:
    <IfModule mod_alias.c>
    Alias /robots.txt /home/username/sites/domain.com/domain/domain/media/robots.txt
    Alias /site_media /home/username/sites/domain.com/domain/domain/media
    Alias /admin_media /home/username/sites/domain.com/django/contrib/admin/media
    </IfModule>
    
    <IfModule mod_wsgi.c>
    # See the link below for an introduction about this mod_wsgi config.
    # http://groups.google.com/group/modwsgi/browse_thread/thread/60cb0ec3041ac1bc/2c547b701c4d74aa
    
    WSGIScriptAlias / /home/username/public_html/domain.wsgi
    WSGIDaemonProcess domain processes=7 threads=1 display-name=%{GROUP}
    WSGIProcessGroup domain
    WSGIApplicationGroup %{GLOBAL}
    </IfModule>
    
    # This fixes the broken ErrorDocument directive we inherit that breaks auth
    # if we use a WSGI app.
    ErrorDocument 401 "Authentication Error"
    ErrorDocument 403 "Forbidden"
    The generated httpd.conf would then contain this section:
    Code:
    # DO NOT EDIT. AUTOMATICALLY GENERATED.  IF YOU NEED TO MAKE A CHANGE PLEASE USE THE INCLUDE FILES.
    
    <VirtualHost xx.xx.xx.xx:80>
        ServerName domain.parent-domain.com
        ServerAlias www.domain.com www.domain.parent-domain.com domain.com
        DocumentRoot /home/username/sites/domain.com
        ServerAdmin webmaster@domain.parent-domain.com
        UseCanonicalName Off
        CustomLog /usr/local/apache/domlogs/domain.parent-domain.com combined
        CustomLog /usr/local/apache/domlogs/domain.parent-domain.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
        ## User username # Needed for Cpanel::ApacheConf
        <IfModule mod_suphp.c>
            suPHP_UserGroup username username
        </IfModule>
        <IfModule !mod_disable_suexec.c>
            <IfModule !mod_ruid2.c>
                SuexecUserGroup username username
            </IfModule>
        </IfModule>
        <IfModule mod_ruid2.c>
            RUidGid username username
        </IfModule>
        ScriptAlias /cgi-bin/ /home/username/sites/domain.com/cgi-bin/
    
        Include "/usr/local/apache/conf/userdata/std/2/username/domain.com/*.conf"
    
    </VirtualHost>
    The Include occurs at the end of the virtualhost section but still within it. Try removing any VirtualHost tags you have and write your code as if it's already inside the virtualhost tags. Hope this helps, I'm sure you've already got it by now. ;)
     
  9. cPanelKenneth

    cPanelKenneth cPanel Development
    Staff Member

    Joined:
    Apr 7, 2006
    Messages:
    4,461
    Likes Received:
    22
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    Documentation:
    * Changes Contained within a VirtualHost Directive
    * Include Editor

    To add a custom VirtualHost you should use the IncludeEditor within WHM. As noted in the first documentation link, and various posts in this thread, the includes you manually create in /usr/local/apache/conf/userdata are pulled directly into VirtualHost blocks. They are meant to modify VirtualHosts, not create new ones.


    Editing the data in /var/cpanel/userdata is strongly discouraged. The contents are not documented, nor generally meant for human modification.
     
  10. amit_roy

    amit_roy Member

    Joined:
    Oct 19, 2012
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    We tried to follow the steps listed here ,:
    - Created the respective directories
    - Created a .conf file in the required directory
    - Added the virtualhost entries there
    - Ran
    Code:
     /usr/local/cpanel/bin/apache_conf_distiller --update
    and
    Code:
    /scripts/rebuildhttpdconf
    and it gave us the virtualhost contained within another virtualhost error.

    We then had a look at our httpd.conf file which usually has a lot of info. The following section at the top proved helpful for us
    We gave it a second shot which was as follows:

    - We listened to our httpd.conf and created a ssl_vhost.local file at /var/cpanel/templates/apache2/

    - Added the nameVirtualHost directive there for port 443

    - Added the virtualhost entries for port 443 there

    - checked if apache passed basic config test /usr/local/apache/bin/apachectl configtest

    - We didnt use # /usr/local/apache/bin/apachectl restart , but rather restarted apache from WHM because the apache didnt restart when we used this command

    - Test if apache restarted successfully by checking its status # /usr/local/apache/bin/apachectl status

    - To have modifications retained, all modifications must be checked into configuration system by running
    /usr/local/cpanel/bin/apache_conf_distiller –update

    - To see if your changes will be conserved, regenerate the Apache configuration file by running
    /usr/local/cpanel/bin/build_apache_conf instead of /scripts/rebuildhttpdconf

    and finally we were able to get the virtualhost entries saved permanently. I hope this helps peoples. We are still making notes and looking into it to make sure we got everything correct.
     
  11. amit_roy

    amit_roy Member

    Joined:
    Oct 19, 2012
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Forgot to mention we don't have easyApache yet on WHM. Seems Inmotion hasn't updated the WHM yet for our VPS.
     
Loading...

Share This Page