Forcing .cpanel .whm and .webmail subdomains to server hostname w/ SSL
We've had quite a few customers get accustomed to accessing their accounts via the cpanel.(domain.com) and webmail.(domain.com). For obvious reasons we force SSL on these subdomains (tweak settings) as they're passing login information through them. The issue with this is that they all get certificate errors as cPanel will use the server's hostname SSL certificate. This worries quite a few users and we've gotten a few complaints.
Since I don't see any option to have the subdomains redirected to the HOSTNAME.com:2083, etc in tweak settings (like you can do for domain.com/cpanel) came up with this procedure to modify the httpd.conf to force this redirect:
# cp /var/cpanel/templates/apache2_4/main.default /var/cpanel/templates/apache2_4/main.local
# nano /var/cpanel/templates/apache2_4/main.local
replace (2 locations) :
RewriteEngine On
RewriteCond %{HTTP_HOST} !^[% wildcard_safe(servername) %]$
RewriteCond %{HTTP_HOST} ^cpanel\.
RewriteRule ^/(.*) http://127.0.0.1:2082/$1 [P]
RewriteCond %{HTTP_HOST} !^[% wildcard_safe(servername) %]$
RewriteCond %{HTTP_HOST} ^webmail\.
RewriteRule ^/(.*) http://127.0.0.1:2095/$1 [P]
RewriteCond %{HTTP_HOST} !^[% wildcard_safe(servername) %]$
RewriteCond %{HTTP_HOST} ^whm\.
RewriteRule ^/(.*) http://127.0.0.1:2086/$1 [P]
with:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^webmail\.* [OR]
RewriteCond %{HTTP_HOST} ^www\.webmail\.*
RewriteRule ^/?$ "https\:\/\/hostname\.com\:2096" [R=301,L]
RewriteCond %{HTTP_HOST} ^cpanel\.* [OR]
RewriteCond %{HTTP_HOST} ^www\.cpanel\.*
RewriteRule ^/?$ "https\:\/\/hostname\.com\:2083" [R=301,L]
RewriteCond %{HTTP_HOST} ^whm\.* [OR]
RewriteCond %{HTTP_HOST} ^www\.whm\.*
RewriteRule ^/?$ "https\:\/\/hostname\.com\:2087" [R=301,L]
rebuild httpd.conf and restart apache:
# /scripts/rebuildhttpdconf
# /etc/init.d/httpd restart
-
Hello :) Thank you for sharing this workaround. Please note that user-submitted workarounds are not tested or supported by cPanel. We encourage everyone to review all aspects of workarounds before implementing them on a production server. Thank you. 0
Please sign in to leave a comment.
Comments
1 comment