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.

SSL wildcard use with subdomains

Discussion in 'General Discussion' started by guy100, Jun 15, 2012.

  1. guy100

    guy100 Registered

    Joined:
    Jun 15, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    I have install one wildcard ssl to my server, but i have some problem.

    when i run https://example.com it works

    but when i run https://new.example.com it point me to https://example.com

    Right now i use one dedicate ip for all subdomains.

    I read a little the forum and im not sure if i can use one dedicated ip for all secure subdomains or i need as many ip as the subdomains.

    Im wait for your help.
     
  2. guy100

    guy100 Registered

    Joined:
    Jun 15, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    With search i have found the solution and put it here for to help anyone search this

    First, you need to generate a CSR. When it asks for the hostname (the domain), you'll enter the following:

    *.yourdomain.com

    Once the CSR is generated, go ahead and purchase your SSL certificate.

    When you receive the certificate key, you can now install the certificate. You'll need the following:

    Certificate Key
    Private RSA Key
    CA Bundle (optional)

    Both the Certificate Key and CA Bundle are provided after you order the SSL certificate and it's been approved. The Private RSA Key is provided when you generate the CSR.

    Normally, when you install an SSL certificate, it fills in the domain name, IP address, and username. However, for a wildcard SSL in cPanel, you will need to change the domain name to the following:

    domain.com

    Basically, you're removing the asterisk and period before the actual domain name.

    Now, in doing this, when cPanel generates the block of code in the httpd.conf file, it's going to set the document root to the following:

    /home/<username>/public_html

    And that's ok, but if you want to setup subdomains outside the public_html directory, then the wildcard SSL won't work unless you manually modify the httpd.conf file, which you really don't want to do.

    So, to get around this, we need to use mod_rewrite to redirect requests to the appropriate directory.

    When you actually set up a subdomain, you can set the path to the folder, and it's probably best to do something like this:

    /home/<username>/public_html/subdomains/<subdomain>

    In the .htaccess file in your public_html directory, for each subdomain that needs an SSL certificate, you will need to add the following:

    RewriteEngine on
    RewriteCond %{SERVER_PORT} ^443$
    RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/sub/
    RewriteRule ^(.*) /sub/$1


    You'll want to replace sub with the appropriate data, of course.


    For each subfolder you need the same lines, for example for sub1 and sub2

    RewriteEngine on
    RewriteCond %{SERVER_PORT} ^443$
    RewriteCond %{HTTP_HOST} ^sub1\.domain\.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/sub1/
    RewriteRule ^(.*) /sub1/$1
    RewriteCond %{SERVER_PORT} ^443$
    RewriteCond %{HTTP_HOST} ^sub2\.domain\.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/sub2/
    RewriteRule ^(.*) /sub2/$1



    In case you need to redirect all HTTP request to HTTPS you can add after rewriteengine on

    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
     
    #2 guy100, Jun 16, 2012
    Last edited: Jun 16, 2012
  3. NixTree

    NixTree Well-Known Member

    Joined:
    Aug 19, 2010
    Messages:
    387
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Gods Own Country
    cPanel Access Level:
    Root Administrator
    Hello,

    I have had the same problem once and I did manage it with redirects upto an extent. But when the redirect rules started to increase, I used the following trick to have a clean solution.

    Some techie thoughts » cPanel Wildcard SSL

    Thank you.
     
  4. norutaj

    norutaj Registered

    Joined:
    Jun 27, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Hello,
    The url you provided is not working. I am adding new subdomains all the time so adding to the redirect rules one at a time will not work for me. Would you please let me know of that trick you mentioned?

    Thank you,
    Norutaj
     
  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
  6. norutaj

    norutaj Registered

    Joined:
    Jun 27, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Hello,
    Is there a way to use some sort of variable for the subdomain instead of adding a set of rules for each subdomain one at a time? I will have thousands of subdomains and adding to the rules will be unmanagable.
    In other words can we write a set of rules that can be used for all subdomains (replace sub1, sub2, ... with a variable so that we don't have to repeat the rules each time a new subdomain is added).

    Thank you,
     
  7. NixTree

    NixTree Well-Known Member

    Joined:
    Aug 19, 2010
    Messages:
    387
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Gods Own Country
    cPanel Access Level:
    Root Administrator
    Sorry; the URL should work now :)
     
  8. norutaj

    norutaj Registered

    Joined:
    Jun 27, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Website Owner
    Thanks I did take a look but do you have a way to do this preferably via .htacess? Like the post above but somehow has regex pattern matching of the "subdomain" without having to add new set of rules all the time for newly created subdomains.
     
  9. NixTree

    NixTree Well-Known Member

    Joined:
    Aug 19, 2010
    Messages:
    387
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Gods Own Country
    cPanel Access Level:
    Root Administrator
    Hello,

    If all your sub-domains have a common Document root, you can add a wildcrd redirect rule for SSL like above and escape from redirect rule for each sub-domains. If they have separate Doc Root, I am afraid I don't know another option. What the particualr post suggests a "clean" way to install SSL for sub-domains.

    Thank you.
     
Loading...

Share This Page