SSL TLS part 2 - Let's Encrypt
Let's Encrypt is a relatively new (public beta) free, automated, and open source certificate authority.
Installation
Open a terminal on your webserver:
1 | $ cd ~ |
This will install all required dependencies.
Let's Encrypt supports Apache out of the box, but I use Nginx.
Preparing Nginx
GitHub user renchap wrote a guide for using Let's Encrypt for Nginx and it worked for me.
First up, the Nginx configuration. I'm using the DigitalOcean Ghost image, so editing my Nginx configuration is done with:
1 | $ vim /etc/nginx/sites-enabled/ghost |
In the server block, add a new location block:
1 | location '/.well-known/acme-challenge' { |
and restart Nginx:
1 | $ service nginx restart |
Generate the certificate
Next, we'll set up our environment:
1 | $ export DOMAINS="-d your_site.com" |
My key was placed in /etc/letsencrypt/live/celeodor.com. Let's update Nginx to use that key now.
Nginx configuration
Back in your site's Nginx configuration file, edit the server block to add these lines:
1 | listen 443 ssl; |
And restart Nginx:
1 | $ service nginx restart |
Navigate to https://your_site.com and verify that the certificate is being read.
Automatically renew certificate
The Let's Encrypt certificate only lasts for 90 days, but we can renew it before that. Renchap's guide recommends doing so every 60 days.
We'll put the required commands in a script:
1 | $ vim ~/ssl_renew.sh |
1 | export DOMAINS="-d your_site.com" |
1 | $ service nginx reload |
Mark it as executable:
1 | $ chmod +x ~/ssl_renew.sh |
Now we'll toss that into a cron job to run every 60 days:
1 | $ crontab -e |
Redirect all HTTP traffic to HTTPS
If your new certificate is working correctly and you'd like to direct all HTTP traffic to HTTPS, your Nginx site configuration file will need some editing. We'll have 2 server blocks: 1 for catching the HTTP traffic and redirecting it to HTTPS, and the other for actual serving our website over HTTPS:
1 | server { |
Edit to your tastes, and then restart Nginx:
1 | $ service nginx restart |
Navigate to your site's homepage in HTTP and verify that you're redirected to the HTTPS URL.
SSL Labs Rating
With my self-signed SSL cert, this site scored a "T" on SSL Labs. This time around, it scored a "B".