Site now SSL by default


Google recently announced that it is going to start prioritising websites that offer HTTPS by default in its search engine results. At first, the positive effect will be small to give webmasters time to switch to HTTPS, but it will gradually become more of a significant signal. This is a good thing for the internet: SSL doesn't cost much for webhosts, and it makes it more difficult to spy on everyone all the time! The Electronic Frontier Foundation praised the decision calling it a "bold and welcome move to protect users".

I wanted to start offering some of the services I run on my server to other friends and family, and I couldn't easily install the CAcert root on all of their devices, so this seemed like a good time to purchase a cert. The following describes how I configured the various services (Apache, Postfix, Dovecot) to use the new certificate from COMODO.

Differences to CAcert certificate

Until now, I have used a certificate signed by CAcert for the site and used Apache's mod_rewrite to redirect unauthenticated users (everyone except me) back to http. I chose to do this because unless the CAcert root was installed on the client machine, the users would get a browser error; I also didn't want Google crawling the HTTPS site and penalising me for having duplicate content (http and https).

Configuring Apache and the other services to use the cert signed by CAcert was easy because it was signed directly by the CAcert root: I just had to give Apache a path to the new certificate file, it sent the cert to clients when they made a connection, and it was accepted because it was signed by a trusted root certificate. However, commercial certificate authorities generally don't use their root certificates to validate domains because having the root key in constant use increases the likelihood that the key could be compromised. Instead, they use the root key to sign an intermediate certificate, and then use the intermediate key to validate domains. If they didn't do this and the root key was compromised, every operating system would have to push an update to remove the compromised root certificate from the trusted certificate store on users' machines; this way, if the intermediate key is compromised the certificate authority can revoke the intermediate cert and generate a new one without the root certificate being affected.

The small downside of this is that Apache now needs to send a string of certs to each client containing every certificate between yours and the root cert, or the client will just check to see if your cert was signed directly by a root CA in its trusted certificate store, and reject it if it wasn't. The string of certs forms a chain of trust, i.e. "the was signed by intermediate_cert which was signed by root_ca". So, the first thing I had to do was concatenate the certificate files to make one jumbo certificate file.

Creating a certificate bundle

Comodo sent me a .zip archive containing the following files:

  • AddTrustExternalCARoot.crt
  • COMODORSAAddTrustCA.crt
  • COMODORSADomainValidationSecureServerCA.crt
  • samhobbs_co_uk.crt

To unzip the archive use the unzip command:

mkdir ~/certs
mv ~/certs/
cd ~/certs

The order of the certs in the concatenated file is important: you want your certificate at the top of the file, the one that signed your cert (intermediate1) below that, and the one that signed that one (intermediate2) below that. The root certificate should be left off the file: each client will already have a copy of this file in its trusted certificate store... and if they don't then sending them it won't help, the cert will still be rejected! Actually, the RFC for TLS says that you MAY include the anchor (root cert), which means it will work either way... but the QUALYS SSL Labs test, which we will be using later, will flag it up as an anomaly if you do.

So... which file is which? You can get information about certs in a human readable format by using this command:

openssl x509 -text -in /path/to/your/cert.crt

example output:

        Version: 3 (0x2)                                                                     
        Serial Number:                                                                       
    Signature Algorithm: sha256WithRSAEncryption                                             
        Issuer: C=GB, ST=Greater Manchester, L=Salford, O=COMODO CA Limited, CN=COMODO RSA Domain Validation Secure Server CA                                                             
            Not Before: Aug 15 00:00:00 2014 GMT
            Not After : Aug 14 23:59:59 2019 GMT
        Subject: OU=Domain Control Validated, OU=PositiveSSL,
        Subject Public Key Info:
            Public Key Algorithm: rsaEncryption
                Public-Key: (2048 bit)
                Exponent: 65537 (0x10001)
        X509v3 extensions:
            X509v3 Authority Key Identifier: 

            X509v3 Subject Key Identifier: 
            X509v3 Key Usage: critical
                Digital Signature, Key Encipherment
            X509v3 Basic Constraints: critical
            X509v3 Extended Key Usage: 
                TLS Web Server Authentication, TLS Web Client Authentication
            X509v3 Certificate Policies: 

            X509v3 CRL Distribution Points: 

                Full Name:

            Authority Information Access: 
                CA Issuers - URI:
                OCSP - URI:

            X509v3 Subject Alternative Name: 
    Signature Algorithm: sha256WithRSAEncryption

And if you just want to know who issued the cert (who signed it) then use this command:

openssl x509 -noout -in samhobbs_co_uk.crt -issuer

Example output:

issuer= /C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Domain Validation Secure Server CA

So we can see that my cert was signed by COMODORSADomainValidationSecureServerCA.crt. Using the same command on the other certs reveals that the order, from root to my cert, is:

  1. AddTrustExternalCARoot.crt (ROOT)
  2. COMODORSAAddTrustCA.crt
  3. COMODORSADomainValidationSecureServerCA.crt
  4. samhobbs_co_uk.crt

So, to combine all of these files into one we can use the cat command, listing them in reverse order and omitting the root cert:

cat samhobbs_co_uk.crt COMODORSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt >

Configuring Services

So, now that we have a combined certificate file, let's configure Apache2, Dovecot and Postfix to use it:

In the following examples, I'm using these paths as an example:

  • The certificate (on its own) is located at /etc/ssl/certs/
  • The certificate bundle is located at /etc/ssl/certs/
  • The key file is located at /etc/ssl/private/


In your postfix configuration file /etc/postfix/, find these two parameters and edit them to match these lines:


As you can see, Postfix only needs the certificate bundle and the key file; the certificate file on its own is not used.


The SSL configuration for Dovecot is found at /etc/dovecot/conf.d/10-ssl.conf, and needs the key file and the certificate bundle, similar to Postfix:

ssl_cert = </etc/ssl/certs/
ssl_key = </etc/ssl/private/

NB: the < isn't a mistake, don't leave it out!


Apache2 is the odd one out here, because it requires three parameters in versions before 2.4.8, like so:

SSLCertificateFile      /etc/ssl/certs/
SSLCertificateChainFile      /etc/ssl/certs/
SSLCertificateKeyFile      /etc/ssl/private/

I.e. the cert on its own, the certificate bundle and the key file.

In new versions (greater than 2.4.8) things have improved: SSLCertificateChainFile is depreciated; SSLCertificateFile was extended so that you can pass it a certificate bundle... so now Apache just needs two parameters:

SSLCertificateFile      /etc/ssl/certs/
SSLCertificateKeyFile      /etc/ssl/private/

If you're not sure which version of Apache you're running, you can check with this command:

apache2 -v

At the time of writing (01 Sep 2014), the version of Apache2 in the Ubuntu 14.04 repositories is 2.4.7 and the version in the Raspbian/Debian stable repos is 2.2.22; both of these packages use the "old way" but Ubuntu will soon get the new version.

HTTP Strict Transport Security (HSTS)

If your site is HTTPS only, you can make use of a technology called HTTP Strict Transport Security (HSTS), where Apache sends a header to the client's browser that tells it to always connect with HTTPS. This site is using HSTS now: if you have visited before and you type in your browser it will rewrite to before it sends a request to my server.

This is different to rewriting HTTP to HTTPS on the server because the rewrite is done client side, and can help prevent certain kinds of Man In The Middle (MITM) attacks.

Note that you still need to have a HTTP virtualhost that rewrites to HTTPS because this only works when someone has visited to the site before: new users will need a server-side rewrite before their browser has stored the header.

Setting up HSTS is really simple: all you need to do is add this to your HTTPS virtualhost:

Header add Strict-Transport-Security "max-age=15768000"

And then reload Apache:

sudo service apache2 reload

Obviously, don't do this for sites where you actually want to have separate HTTP and HTTPS sites on the same domain name, or you won't be able to access the HTTP site without clearing your cache to remove the header.

Perfect Forward Secrecy

While we are talking about SSL, I thought I'd mention Perfect Forward Secrecy (PFS). This is technology that helps protect users by ensuring that if a SSL key is decrypted in the future it couldn't be used to decrypt past sessions that were captured (by security services or your ISP, for example).

Or in other words (from the EFF article below):

When an encrypted connection uses perfect forward secrecy, that means that the session keys the server generates are truly ephemeral, and even somebody with access to the secret key can't later derive the relevant session key that would allow her to decrypt any particular HTTPS session. So intercepted encrypted data is protected from prying eyes long into the future, even if the website's secret key is later compromised.

You can read more about PFS on the EFF's website.

So, how do we configure PFS on Apache? Luckily, there are already some useful guides at and, and the Mozilla wiki is useful too.

I don't have any special knowledge of the various ciphers used in SSL/TLS, so the configuration below was taken from the Mozilla wiki, using the backward compatible ciphersuite. The order of the list prioritises strong ciphers that support forward secrecy.

First, you need Apache 2.3.3 or higher (see earlier in this article for how to check your version).
Next, put this inside your SSL virtualhost:

SSLProtocol             all -SSLv2
SSLHonorCipherOrder     on
SSLCompression          off

Now test your configuration with the Qualys SSL Labs test!

You can read some more about VirtualHost files on Apache2 in this tutorial of mine.



Was it this post? That's me! Lol.

Well done for figuring it out. I feel like I learn way more when I have had to troubleshoot problems than when everything goes well first time, hopefully the same is true for you!


Hi Sam,
I consider to add a commercial SSL such as yours. There are two things I want to your advices. One is the root.crt. What is the exact purpose on it? My friend told me a free SSL-Let's Encrypted. Actually, I refer some on-line tutorials and try to install on my apache but fail to complete installation. This SSL didn't support wildcard, but I primally thought I could apply each for each. (i.e. one for, two for, and etc...) Yet I didn't install this SSL completely. Otherwise, there are some constrains on it such as a limit on clients connecting times. So, I decide to give up to research it currently. Here it's the web address( I saw the root.pem. It seems to purpose to prolong and to revoke SSL certificate. I am not sure that I am right or wrong on this idea? There aren't any steps to concatenate about root(AddTrustExternalCARoot.crt (ROOT)). Briefly, the CAcert is 2 layer hierarchy(SelfSigned) and the most commercial one is 3 layer hierarchy. Hope I didn't figure out wrongly. Haha!

The second question is about the commercial COMODO. Their production lists are quite long. However, I consider wildcard this feature. There are fairly economic price from resellers who I search on-line. May I know your details of your procurement, such as price or specific product name?

Really thanks your devotion and efforts on teaching us and making us successfully build sites.
Best regards,


I haven't used Let's Encrypt, but I've heard good things.

When you ask about root.crt, do you mean the copy of the company's root certificate that should be pre-installed in your OS? It is the public part of their key, used to identify them when they sign a certificate. Your OS knows that certificates signed by the key that matches that root certificate have been validated by the company, so it trusts them. The intermediate certs do the same thing (root has validated this person is trustworthy to sign other certificates, and they have signed this certificate, therefore it is trusted).

Does that help?

As for your question, I used Comodo positive SSL, which was a reasonable price. The website in that link is a decent price comparison for certificates.


Hi Sam,
Thanks your answer and then I refer some articles about "public key" algorithm. I read a book that is using a toner method to illustrate the operation principle. (i.e. One uses "the public color" and "a private color" to mix a color for exchanging data and then get the other side's mixed color to difference(i.e. to subtract) "the public color" to get the other side's assigned color.) And Let's Encrypt is using "public key" twice for enhancing its reliability, isn't it? I share my installation experience.

Here I post my virtual host configuration. The # sign might not be necessary lines. What I got bothered with "/" on Redirect "/" "" this line. This made me stocked while I didn't set up a "/" on the tail. Because the directory got wrong on "". Behind your address, it must be a "/" to separate the /.well-known. My command is "sudo certbot-auto certonly webroot -w /var/www/mywebsite/ -d". If it is also valid to combine the domain together(i.e. It's without www on the DNS setting.), there is to add "-d mydomain" right after your previous domain. The command is "sudo certbot-auto certonly webroot -w /var/www/mywebsite/ -d -d". This case is specific on your virtual host owning "ServerAlias" this conf. file. Otherwise, I use drupal7 and there is a patch necessary for .well-known directory. Kindly refer this Thanks again.

#============================ MYWEBSITE ============================

# DocumentRoot /var/www/mywebsite/
# ServerAdmin

# Options FollowSymLinks
# AllowOverride All
# Order allow,deny
# allow from all

# ErrorLog ${APACHE_LOG_DIR}/mywebsite/error.log
# LogLevel warn
# CustomLog ${APACHE_LOG_DIR}/mywebsite/ssl_access.log combined
Redirect "/" ""

#============================ SSL_MYWEBSITE============================

DocumentRoot /var/www/mywebsite/

Options FollowSymLinks
AllowOverride All
Order allow,deny
allow from all

ErrorLog ${APACHE_LOG_DIR}/mywebiste/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/mywebsite/ssl_access.log combined

SSLEngine on
# SSLCertificateFile /etc/ssl/certs/mycacert.crt
# SSLCertificateKeyFile /etc/ssl/private/mycacert.key
SSLCertificateFile /etc/letsencrypt/live/
SSLCertificateKeyFile /etc/letsencrypt/live/
SSLCertificateChainFile /etc/letsencrypt/live/
SSLCACertificateFile /etc/letsencrypt/live/

Hi Sam,

I purchased the Comodo Positive SSL and followed your tutorial on the Configuring Services part.

Apache [2.4.10 (Raspbian)], failed to load when i put the .ca-bundle in /etc/apache2/sites-available/default-ssl.conf due to a key - certificate mismatch (cat /var/log/apache2/error.log)


it loaded normally after i put the .crt instead of the .ca-bundle and rebooted.

So my apache configuration looks like this:

SSLCertificateFile /etc/ssl/certs/your_certificate.crt
SSLCertificateKeyFile /etc/ssl/private/your_key.key

Is putting the .crt alone in the configuration file a proper solution?

Both .crt and .ca-bundle are located in /etc/ssl/certs/ but the bundle file does not contain the crt itself as far as checked.
Also the private key and the .ca-bundle do not match in but the .crt does..

I find it kind of strange but i thought i shoud share it here because it could save someone the time to figure it out (if that is a solution indeed).

Thank you for your useful and well written tutorials!

Unfortunately i have to confirm that the above solution is not 100% correct. gave the website a "B" rating due to the fact that the .ca-bundle is not present.

So, for anyone having the same key certificate mismatch problems the proper solution is:

1) Check your key/csr - certificate and key/csr - ca-bundle at
If you find that the ca-bundle does not match the key but the cert does you have the same problem as me.
If not something is wrong with your key / csr and you have to start over.

2) Either put both csr and ca-bundle in your apache configuration (use the old way) OR combine them in a new ca-bundle that contains everything. Use Sam's "Creating a certificate bundle" instructions above.

After these steps gave the website an A+ rating, so i think i can consider this solved.

Thanks for updating your comment. So do you think your issue was a key and cert that didn't match?

Whatever you do, don't paste your key into that website (or anywhere, actually - it's private for a reason!).


Hey Sam!

Yes, I think my problem was the fact that the crt file is not contained in the ca-bundle, resulting to a key - certificate mismatch.

Although they give you the option to paste your private key for checking I did not use that.
I used my csr instead.

Do you think that this is something to be avoided as well?


That's good. The CSR only contains your public key, so that's absolutely fine to share.


Hi Sam,

I have been following the Q/A sessions concerning SSL. You mention that you use Positive SSL which will support and Now I use squirrelmail with a Virtual host as and currently use a wildcard cert from CaCert as *

It is not clear how a Positive SSL can cover my web-site at as well as A Positive SSL Wildcard is significantly more expensive. I think I am missing something since squirrelMail uses the same Apache infrastructure as the web page.

How does a Positive SSL cert cover a sub-domain?

Thanks ... John

Hi John,

Unfortunately you have to buy a separate cert for the subdomain, or change your DNS settings so that you only use and (e.g. website at and email server at if they are separate servers).


Hi Sam,

Thanks for the reply. I should have mentioned that the web-site and the mail server are on the same Raspberry Pi. So they are not separate servers. Will that make a difference? You have my email address so you can look at DNS and MX records if that would help.

If I have to buy two Positive SSL certificates, I suppose I would have to make separate certs directories: one for postfix/dovecot and a second for Apache/Squirrelmail? Is that correct?

Or continue to use CaCert certificates for the mail server; and Comodo for the Apache/Squirrelmail. Does that make sense?


Hi Sam,

Apologies if I am being slow. If I change the MX record as you suggest, presumably will no longer be recognised?


What do you mean, is your email address

I was assuming you just created a mail. subdomain due to convention and pointed to that in the MX record for yourdomain.con (i.e. your email address is


Hi Sam,

My mistake: I should have been clearer:

There are DNS A records for: and and which all point to my static IP address
There is an MX record for

My formal mail address is

But: for web-mail (via squirrel mail), the web-mail address is: and in the Virtual Host for .443 there is this:

<VirtualHost *:443>
DocumentRoot /usr/share/squirrelmail

So, while there is a sub-domain, ( it is only there for web-mail access.

The question then is: will a single Positive SSL certificate be sufficient for this infrastructure?

Thanks (again)


Hi Sam,

Before going to Comodo I tried this experiment.

1. I am currently using a * wildcard from CaCert.
2. I requested a new certificate for - ie. not a wildcard
3. I installed key and cert into /etc/ssl/private and /etc/ssl/certs respectively (obviously with different names from the wildcard key/crt)
4. Changed all .key/.crt references in postfix/dovecot/apache2 to the new names and
5. Restarted postfix/dovecot/apache2

As expected, normal mail service resumes and web-site comes alive - although Firefox objects to a non-trusted certificate. Easily fixed

But also works with new certificates - after another Firefox fix.

So I can see what is needed - and I can get a second cert for if it is needed. At least I know now that a Comodo wild SSL is not required.

As usual, thanks for help.


Hi Sam,

End of story...I visited namecheap; requested PositiveSSL; installation was simple; postfix/dovecot/apache2 updated. I can see now that a second SSL for squirrelmail would complete the job.

It was useful using CaCert as a dry run before making a commitment to Comodo.

Thanks again...John


Add new comment