/ tech

How to add A+ SSL encryption to Ghost using Let's Encrypt

Guide to add a free, self-renewing, A+ SSL certificat from Let's Encrypt with HSTS to your site.



Certbot takes a lot of load off your shoulders and provides you an easy tool to generate and updates your let's encrypt certifcates. Install in Linux is as easy as:

wget https://dl.eff.org/certbot-auto
chmod a+x ./certbot-auto

To make it work, install the Python package cryptography and it's dependencies.

 sudo apt update
 sudo apt install -y libssl-dev
 sudo pip install cryptography

Next we execute the binary and generate the certificate.

  sudo service nginx stop
  sudo ./certbot-auto certonly \
      --standalone \
      -d ghost.oceanbased.ch \
      --email foo@bar.com \
      --non-interactive \

After this, the certifcates are available at /etc/letsencrypt/live/ghost.oceanbased.ch/.


To reach A+ level, we first have to generate a new Diffie-Hellman key.

 cd /etc/ssl/certs
 sudo openssl dhparam -out dhparam.pem 2048

This will take a while - go and grab a cup of coffee ;)

After the process has finished, change your NGiNX config.

Open your config:

 sudo vim /etc/nginc/sites-available/ghost.conf


server {
    # Enforce HTTPS
    listen 80 default_server;
    server_name ghost.oceanbased.ch;
    return 301 https://ghost.oceanbased.ch$request_uri;

server {
    listen 443 default_server ssl;

    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;

    ssl_dhparam /etc/ssl/certs/dhparam.pem;

    access_log /var/log/nginx/ghost.oceanbased.ch.log;
    error_log  /var/log/nginx/ghost.oceanbased.ch-error.log error;

    server_name ghost.oceanbased.ch;

    charset utf-8;

    ssl_certificate           /etc/letsencrypt/live/ghost.oceanbased.ch/fullchain.pem;
    ssl_certificate_key       /etc/letsencrypt/live/ghost.oceanbased.ch/privkey.pem;
    ssl_prefer_server_ciphers on;

    add_header Strict-Transport-Security max-age=31536000 always;

    ssl_stapling on;
    ssl_stapling_verify on;

    try_files $uri $uri/ ;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto https;
      proxy_set_header X-Forwarded-Port 443;
      proxy_set_header Host $host;
      add_header Strict-Transport-Security max-age=31536000 always;


Certbot also takes care of the renewal of your certificate. Add the following to your crontab:

 # open the crontab
 crontab -e
 # add the following line
 0 3 * * * /path/to/certbot-auto renew --quiet


How to add A+ SSL encryption to Ghost using Let's Encrypt
Share this