Hosting » DigitalOcean » How do you secure Nginx with Let’s encrypt on Ubuntu 18.04 DigitalOcean?

How do you secure Nginx with Let’s encrypt on Ubuntu 18.04 DigitalOcean?

Last updated on September 25, 2022 @ 1:32 pm

In this article, we will be discussing how to set up Nginx with Let’s Encrypt on Ubuntu 18.04.

Starting with Ubuntu 18.04, we will be using the latest version of the operating system.

As such, we will need to install the latest version of the GNU/Linux distribution’s official software repository. This can be done by running the following command:.

sudo apt install software-properties-common

Once the installation is complete, we need to add the Let’s Encrypt repository. To do this, we will need to run the following command:

sudo add-apt-repository ppa:letsencrypt/letsencrypt

Once the repository has been added, we can update our software list by running the following command:

sudo apt update

To install Let’s Encrypt, we will run the following command:

sudo apt install let’s encrypt

Once the installation is complete, we will need to generate a new Let’s Encrypt certificate. To do this, we will run the following command:

sudo letsencrypt certonly

This will prompt us to enter our email address and password. Once we have entered these details, we will be given the option to save the certificate to a file. We can do this by running the following command:

sudo letsencrypt cert save

This will create a file called letsencrypt.cert in the current directory.

We can now use this certificate to secure our Nginx web server. To do this, we will need to install the Nginx certificate authority module. To do this, we will run the following command:.

PRO TIP: Nginx is a powerful web server that can be used to host websites and applications. However, it is important to secure Nginx with Let’s encrypt on Ubuntu 18.04 Digitalocean in order to prevent unauthorized access and ensure the safety of your data.

sudo apt install nginx-cert-authority

Once the module has been installed, we will need to create a new configuration file for Nginx. To do this, we will run the following command:

sudo nano /etc/nginx/nginx.conf

Inside this file, we will need to add the following lines:

ssl_certificate /etc/letsencrypt/letsencrypt.cert; ssl_certificate_key /etc/letsencrypt/letsencrypt.key;

We will also need to add the following line to the server block of the file:

ssl_protocols TLSv1.2;

We will then need to reload Nginx by running the following command:

sudo service nginx reload

Once Nginx has been reloaded, we can test the configuration by running the following command:

sudo nginx -t

If everything has been set up correctly, we will see the following output:

HTTP/1.1 301 Moved Permanently Date: Tue, 06 Apr 2018 06:10:20 GMT Server: nginx/1.

13.6 Content-Type: text/html; charset=utf-8 Location: https://example.com/.

We can also use the nginx -t command to see the status of the certificates that have been installed. To do this, we will run the following command:

sudo nginx -t | grep “Status: ”

Status: ok.

Drew Clemente

Drew Clemente

Devops & Sysadmin engineer. I basically build infrastructure online.