How To HTTPS Secure Drupal 8 Running Nginx with Let's Encrypt on Ubuntu 18.04

| Servers | 23 seen

Let's Encrypt have done some very good job, providing SSL certificates that everyone can use absolutely for free. Encrypted HTTPS websites should be default in 2020.

I have been implementing HTTPS secure websites for years. Until now I mostly worked with Drupal 7 websites and for securing them I have been using this guide, back from 2016 - Linode: How To Secure Nginx with Let's Encrypt on Ubuntu 12.04

Now, in 2020, working on a new, Drupal 8 powered, website after then initial web development was completed,  I was looking for an easy way to implement a free SSL certificate from Let's Encrypt.

And here comes this tutorial from Digital Ocean in help: How To Secure Nginx with Let's Encrypt on Ubuntu 18.04

 in 2020, installing, obtaining and renewing an SSL certificate is much easier than it was back in 2016

Before proceeding, make sure you have installed Drupal 8 with Nginix on Ubuntu 18.04,

Non securre Drupal 8 website

Non secure Drupal 8 website

Step 1: Installing Certbot

The first step to using Let’s Encrypt to obtain an SSL certificate is to install the Certbot software on your server.

Certbot is in very active development, so the Certbot packages provided by Ubuntu tend to be outdated. However, the Certbot developers maintain a Ubuntu software repository with up-to-date versions, so we’ll use that repository instead.

First, add the repository:

sudo add-apt-repository ppa:certbot/certbot

You’ll need to press ENTER to accept.

Install Certbot’s Nginx package with apt:

sudo apt install python-certbot-nginx

Certbot is now ready to use, but in order for it to configure SSL for Nginx, we need to verify some of Nginx’s configuration.

Step 2: Obtaining an SSL Certificate

Certbot provides a variety of ways to obtain SSL certificates through plugins. The Nginx plugin will take care of reconfiguring Nginx and reloading the config whenever necessary. To use this plugin, type the following:

sudo certbot --nginx -d optionsbrew.com

This runs certbot with the --nginx plugin, using -d to specify the names we’d like the certificate to be valid for.

If this is your first time running certbot, you will be prompted to enter an email address and agree to the terms of service. After doing so, certbot will communicate with the Let’s Encrypt server, then run a challenge to verify that you control the domain you’re requesting a certificate for.

If that’s successful, certbot will ask how you’d like to configure your HTTPS settings.

Configuring certbot

Select your choice then hit ENTER. The configuration will be updated, and Nginx will reload to pick up the new settings. certbot will wrap up with a message telling you the process was successful and where your certificates are stored:

Your certificates are downloaded, installed, and loaded. Try reloading your website using https:// and notice your browser’s security indicator. It should indicate that the site is properly secured,

Secure HTTPS Drupal 8 site

Secure HTTPS Drupal 8 site

Step 3: Verifying Certbot Auto-Renewal

Let’s Encrypt’s certificates are only valid for ninety days. This is to encourage users to automate their certificate renewal process. The certbot package we installed takes care of this for us by adding a renew script to /etc/cron.d. This script runs twice a day and will automatically renew any certificate that’s within thirty days of expiration.

To test the renewal process, you can do a dry run with certbot:

sudo certbot renew --dry-run

If you see no errors, you’re all set. When necessary, Certbot will renew your certificates and reload Nginx to pick up the changes. If the automated renewal process ever fails, Let’s Encrypt will send a message to the email you specified, warning you when your certificate is about to expire.

Add new comment