How To Secure Nginx with Let's Encrypt on Ubuntu

davidgualvez

David

Posted on March 16, 2023

How To Secure Nginx with Let's Encrypt on Ubuntu

Certbot is a command-line tool that can be used to obtain and manage SSL/TLS certificates for your website. In order to use Certbot with Nginx on Ubuntu, you can follow these steps:

Install Certbot:

sudo apt-get update
sudo apt-get install certbot
Enter fullscreen mode Exit fullscreen mode

Install the Nginx plugin for Certbot:

sudo apt-get install python3-certbot-nginx
Enter fullscreen mode Exit fullscreen mode

Verify that your Nginx server blocks are set up correctly by running:

sudo nginx -t
Enter fullscreen mode Exit fullscreen mode

If the configuration test passes, reload Nginx:

sudo systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode

Use Certbot to obtain a new SSL/TLS certificate for your domain:

sudo certbot --nginx -d example.com -d www.example.com
Enter fullscreen mode Exit fullscreen mode

Replace example.com and www.example.com with your actual domain name(s).

Certbot will guide you through the process of obtaining a new SSL/TLS certificate. You will be prompted to enter your email address and agree to the terms of service. Certbot will then communicate with Let's Encrypt to obtain and install the certificate.

Once the certificate is installed, Certbot will update your Nginx configuration to use HTTPS. You can verify this by running:

sudo nginx -t
Enter fullscreen mode Exit fullscreen mode

If the configuration test passes, reload Nginx:

sudo systemctl reload nginx
Enter fullscreen mode Exit fullscreen mode

Congratulations, your Nginx server should now be configured to use HTTPS with a valid SSL/TLS certificate!

💖 💪 🙅 🚩
davidgualvez
David

Posted on March 16, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related