Search form

Free SSL Certificates with Let's Encrypt (Ubuntu 16)

Running a secure web site is better for yourself and your users. Modern search engines also favor web sites that use SSL/HTTPS, so utilizing SSL is an important aspect of SEO. But buying a new SSL certificate every couple of years can get expensive, particularly if you run multiple web sites or if you want to protect all the subdomains of one site like and

Fortunately, the Let's Encrypt project is offering free SSL certificates so you don't have to buy new certificates every year or two. Even better, the Let's Encrypt certbot utility largely automates certificate management -- including renewal -- so you can focus on updating your web site rather than configuring it.

Let's get started! We're using Ubuntu 16.04 with Nginx.

Step 1: Install the certbot utility

root@ubuntu:/# apt-get install software-properties-common
root@ubuntu:/# add-apt-repository ppa:certbot/certbot
root@ubuntu:/# apt-get update
root@ubuntu:/# apt-get install certbot python-certbot-nginx
root@ubuntu:/# certbot --version
certbot 0.22.2

Step 2: Ensure certbot's settings file is correct

root@ubuntu:/# vi /etc/letsencrypt/cli.ini
# Ensure the RSA key size is 4096
rsa-key-size = 4096

Step 3: Grab a new certificate for your web site

root@ubuntu:/# certbot --nginx certonly -d
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Obtaining a new certificate
Performing the following challenges:
tls-sni-01 challenge for
Waiting for verification...
Cleaning up challenges

 - Congratulations! Your certificate and chain have been saved at:
   Your key file has been saved at:
   Your cert will expire on 2018-07-17. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:
   Donating to EFF:          

root@ubuntu:/# certbot certificates
Saving debug log to /var/log/letsencrypt/letsencrypt.log

Found the following certs:
  Certificate Name:
    Expiry Date: 2018-07-17 18:18:57+00:00 (VALID: 89 days)
    Certificate Path: /etc/letsencrypt/live/
    Private Key Path: /etc/letsencrypt/live/

Note: If you omit the 'certonly' option, certbot will download your certificate and then add the new key and certificate paths to your web site's configuration file (/etc/nginx/sites-available/ If you use the certonly option, as above, certbot will download your new cert but leave your site config untouched. This is the method I prefer.

Step 4: Set up your web site in Nginx

Now you need to make your new private key and certificate available to Nginx. To do this, edit your web site's configuration file (/etc/nginx/sites-available/ and set up a server block with your SSL settings. Be sure to include the paths to your new key and certificate provided by certbot above:

server {
        listen       443 ssl http2;
        listen       [::]:443 ssl http2;
        ssl_certificate /etc/letsencrypt/live/;
        ssl_certificate_key /etc/letsencrypt/live/;


        ssl_prefer_server_ciphers on;
        ssl_dhparam /etc/ssl/certs/dhparams.pem;

To force a redirect from http to https, you can place a server block like this at the top of your config file:

server {
        listen 80;
        listen [::]:80;

        return 301$request_uri;

Step 5: Set up autorenewal

By default, certbot will run every day to check for certificates that need renewal. When a renewal happens, you want Nginx to restart, so simply edit /etc/letsencrypt/cli.ini again and add this line to the end:

renew-hook = systemctl restart nginx

Let's Encrypt certificates are "only" valid for 90 days, but since you don't have to renew them manually anymore, who cares?

The full official documentation of certbot is available at Read the Docs.