How to Secure Nginx with Let’s Encrypt on CentOS 8

Secure Nginx with Let's Encrypt on CentOS 8

In this article, we will have explained the necessary steps to secure Nginx with let’s encrypt on CentOS 8. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Let’s Encrypt is a certificate authority that provides free SSL certificates for the website, operating since April 2016, and supported by companies and internet organizations of the world such as Mozilla, Cisco, Chrome, Akamai, etc.

Secure Nginx with Let’s Encrypt on CentOS

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

Before install the Let’s Encrypt SSL domain should be well accessed and use the Nginx virtual host. Read the tutorial how to install Nginx on CentOS 8.

Step 2. Install Certbot.

The certbot package is not included in the standard CentOS 8 repositories, but it can be downloaded from the vendor’s website:

Next, generate a new set of 2048 bit DH parameters using the following command:

To obtain an SSL certificate for the domain, we’re going to use the Webroot plugin that works by creating a temporary file for validating the requested domain in the ${webroot-path}/.well-known/acme-challenge directory:

To avoid duplicating code, create the following two snippets which will be included in all Nginx server block files:

Once the snippets are created, open the domain server block and include the letsencrypt.conf snippet, as shown below:

Reload Nginx configuration for changes to take effect:

Then, run this command to get a certificate and have Certbot edit your Nginx configuration automatically to serve it, turning on HTTPS access in a single step:

Finally steps, edit your domain server block as follows:

Reload the Nginx service for changes to take effect:

Step 4. Checking your Certificate Status.

You can ensure that Certbot created your SSL certificate correctly by using the SSL Server Test from the cloud security company Qualys. Open the following link in your preferred web browser, replacing with your base domain:

Congratulation, you have learned how to secure Nginx with let’s encrypt on CentOS 8. If you have any question, please leave a comment below.