Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

# /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.

Virtualhost entries:

The two virtualhost entries for the subdomains are:

<VirtualHost xx.xx.144.72:443>
ServerName next.my-personal-website.com
ServerAlias www.next.my-personal-website.com
DocumentRoot /home/myguardi/public_html/next.my-personal-website.com
ServerAdmin webmaster@my-personal-website.com
UseCanonicalName On
CustomLog /usr/local/apache/domlogs/next.my-personal-website.com combined
CustomLog /usr/local/apache/domlogs/next.my-personal-website.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
## User myguardi # Needed for Cpanel::ApacheConf
<IfModule mod_suphp.c>
    suPHP_UserGroup myguardi myguardi
</IfModule>
<IfModule !mod_disable_suexec.c>
    SuexecUserGroup myguardi myguardi
</IfModule>
ScriptAlias /cgi-bin/ /home/myguardi/public_html/next.my-personal-website.com/cgi-bin/
SSLEngine on

SSLCertificateFile /etc/ssl/certs/my-personal-website.com.crt
SSLCertificateKeyFile /etc/ssl/private/my-personal-website.com.key
SSLCACertificateFile /etc/ssl/certs/my-personal-website.com.cabundle
CustomLog /usr/local/apache/domlogs/next.my-personal-website.com-ssl_log combined
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
<Directory "/home/myguardi/public_html/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>

and

<VirtualHost xx.xx.144.72:443>
ServerName blog.my-personal-website.com
ServerAlias www.blog.my-personal-website.com
DocumentRoot /home/myguardi/public_html/blog.my-personal-website.com
ServerAdmin webmaster@my-personal-website.com
UseCanonicalName On
CustomLog /usr/local/apache/domlogs/blog.my-personal-website.com combined
CustomLog /usr/local/apache/domlogs/blog.my-personal-website.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
## User myguardi # Needed for Cpanel::ApacheConf
<IfModule mod_suphp.c>
    suPHP_UserGroup myguardi myguardi
</IfModule>
<IfModule !mod_disable_suexec.c>
    SuexecUserGroup myguardi myguardi
</IfModule>
ScriptAlias /cgi-bin/ /home/myguardi/public_html/blog.my-personal-website.com/cgi-bin/
SSLEngine on

SSLCertificateFile /etc/ssl/certs/my-personal-website.com.crt
SSLCertificateKeyFile /etc/ssl/private/my-personal-website.com.key
SSLCACertificateFile /etc/ssl/certs/my-personal-website.com.cabundle
CustomLog /usr/local/apache/domlogs/blog.my-personal-website.com-ssl_log combined
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
<Directory "/home/myguardi/public_html/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>

and the automatically generated virtualhost entry for the main domain for port 443 is

<VirtualHost xx.xx.144.72:443>
ServerName my-personal-website.com
ServerAlias www.my-personal-website.com
DocumentRoot /home/myguardi/public_html
ServerAdmin webmaster@my-personal-website.com
UseCanonicalName Off
CustomLog /usr/local/apache/domlogs/my-personal-website.com combined
CustomLog /usr/local/apache/domlogs/my-personal-website.com-bytes_log "%{%s}t %I .\n%{%s}t %O ."
## User myguardi # Needed for Cpanel::ApacheConf
<IfModule mod_suphp.c>
    suPHP_UserGroup myguardi myguardi
</IfModule>
<IfModule !mod_disable_suexec.c>
    SuexecUserGroup myguardi myguardi
</IfModule>
ScriptAlias /cgi-bin/ /home/myguardi/public_html/cgi-bin/
SSLEngine on

SSLCertificateFile /etc/ssl/certs/my-personal-website.com.crt
SSLCertificateKeyFile /etc/ssl/private/my-personal-website.com.key
SSLCACertificateFile /etc/ssl/certs/my-personal-website.com.cabundle
CustomLog /usr/local/apache/domlogs/my-personal-website.com-ssl_log combined
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
<Directory "/home/myguardi/public_html/cgi-bin">
    SSLOptions +StdEnvVars
</Directory>

# To customize this VirtualHost use an include file at the following location
# Include "/usr/local/apache/conf/userdata/ssl/2/myguardi/my-personal-website.com/*.conf"

I really appreciate if somebody can tell me how to proceed on this. Thank you.

Update: Include directives present are:

`Include "/usr/local/apache/conf/includes/pre_main_global.conf"
Include "/usr/local/apache/conf/includes/pre_main_2.conf"

Include "/usr/local/apache/conf/php.conf"
Include "/usr/local/apache/conf/includes/errordocument.conf"
Include "/usr/local/apache/conf/modsec2.conf"

Include "/usr/local/apache/conf/includes/pre_virtualhost_global.conf"
Include "/usr/local/apache/conf/includes/pre_virtualhost_2.conf" `

These are the entries that are generated before any virtualhost entry is defined. Towards the end of the httpd.conf file , the following two entries are added

Include "/usr/local/apache/conf/includes/post_virtualhost_global.conf"
Include "/usr/local/apache/conf/includes/post_virtualhost_2.conf"

I posted older httpd.conf file before we added the virtualhost entries for sub domains for port 443 here some time ago for another question, if it helps.

share|improve this question
What Include directives are present in the httpd.conf that it generates? – Shane Madden Nov 24 '12 at 8:28

2 Answers

The generated httpd.conf has lot of info.

  • 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.

share|improve this answer

You should include your NameVirtualHost and VirtualHost directives in the following file(s):

 /usr/local/apache/conf/userdata/ssl/2/$user/$domain/$includename.conf

You will probably not find most of these directories on the file system. You should create them. Replace the $user, $domain, $includename.conf with their value.

Once you are done, you should rebuild apache configuration and restart apache. This should do it.

share|improve this answer
Thanks @melsayed for the info. The $user, $domain, I know what values should replace these (the linux user and the domain name), but I don't know what should be the value of $includename.conf – Amitabh Nov 24 '12 at 14:47
That's just something to help you identify the file. I would use domain_ssl.conf for example. – melsayed Nov 24 '12 at 15:34
ok, so I guess if I put the vhost entries there and rebuild httpd.conf it will take the virtualhost entries from there. ALso I wanted to point out I was browsing cpanel forums it says the virtualhost entries are stored in YAML format in the /var/cpanel/userdata/USERNAME . I actually went there 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? – Amitabh Nov 24 '12 at 15:47
Not sure about that. – melsayed Nov 24 '12 at 15:58
I checked out the cpanel forums too. The results are pointing to the precisely same direction. I have to create the file as suggested by you at the given location and put the vhost entries there. I would like o confirm another thing, which is : Should I put the nameVirtualHost directive there too? I will work on updating the VPS tomorrow noon. – Amitabh Nov 24 '12 at 20:00
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.