Secure Nginx with Certbot and Let’s Encrypt on Ubuntu 24.04 LTS

In this article we will learn Secure Nginx with Certbot and Let’s Encrypt on Ubuntu 24.04 LTS. Securing your Nginx server with HTTPS is essential for ensuring data encryption, authenticity, and overall user trust. Let’s Encrypt offers free SSL/TLS certificates and an automated process for certificate issuance and renewal. This guide will walk you through securing Nginx with Certbot (Let’s Encrypt) on Ubuntu 24.04 LTS.

Prerequisites

  • AWS Account with Ubuntu 24.04 LTS EC2 Instance.
  • Domain name pointing to your server (in this guide, we use devopshint.xyz and nginx.DevOpsHint.xyz).

Step #1:Set Up DNS for the Custom Domain

We already have a domain in GoDaddy so first got to GoDaddy.

Go to your account, here “DevOps” and select My Products.

Secure Nginx with Certbot and Let's Encrypt on Ubuntu 24.04 LTS 1

You can see our domain devopshint.xyz below, go to DNS to add the records in it.

Secure Nginx with Certbot and Let's Encrypt on Ubuntu 24.04 LTS 2

In your domain provider’s dashboard, create a DNS A record. Click on Add New Record.

Secure Nginx with Certbot and Let's Encrypt on Ubuntu 24.04 LTS 3
  • Type: A
  • Name: @
  • Value: Your EC2 instance’s public IP address. You must have Elastic IP associated with your EC2 instance.
  • TTL: 1 Hour

Save it.

Secure Nginx with Certbot and Let's Encrypt on Ubuntu 24.04 LTS 4
  • Type: A
  • Name: nginx
  • Value: Your EC2 instance’s public IP address. You must have Elastic IP associated with your EC2 instance.
  • TTL: 1 Hour

Save it.

Secure Nginx with Certbot and Let's Encrypt on Ubuntu 24.04 LTS 5

Step #2:Install Nginx

Before installing any software, ensure your package lists are up-to-date.

sudo apt update
Secure Nginx with Certbot and Let's Encrypt on Ubuntu 24.04 LTS 6

Install the Nginx web server using the following command.

sudo apt install nginx -y
Secure Nginx with Certbot and Let's Encrypt on Ubuntu 24.04 LTS 7

After installation, check the status of the Nginx service to ensure it’s running.

sudo systemctl status nginx
Secure Nginx with Certbot and Let's Encrypt on Ubuntu 24.04 LTS 8

Step #3:Install Certbot for Nginx

Certbot is a tool that automates the process of installing and renewing SSL/TLS certificates from Let’s Encrypt. Install it using the following command.

sudo apt install certbot python3-certbot-nginx -y
Secure Nginx with Certbot and Let's Encrypt on Ubuntu 24.04 LTS 9

Run the following command to obtain and configure an SSL certificate for your domain.

sudo certbot --nginx -d devopshint.xyz -d nginx.DevOpsHint.xyz

Certbot will automatically:

  • Verify domain ownership.
  • Configure Nginx to use the obtained certificates.
  • Reload Nginx to apply the changes.
Secure Nginx with Certbot and Let's Encrypt on Ubuntu 24.04 LTS 10

Once the certificate is issued, open a web browser and access your site at

https://nginx.DevOpsHint.xyz

If the SSL certificate was successfully installed, You should see a secure connection indicator in your browser.

Secure Nginx with Certbot and Let's Encrypt on Ubuntu 24.04 LTS 11
Secure Nginx with Certbot and Let's Encrypt on Ubuntu 24.04 LTS 12
Secure Nginx with Certbot and Let's Encrypt on Ubuntu 24.04 LTS 13

Conclusion:

In conclusion, securing your website with Certbot and Let’s Encrypt is an important step in building a trustworthy and safe online presence. By enabling HTTPS on your Nginx server, you not only protect your users’ data but also improve your website’s ranking in search engines. Following this guide makes the process simple and manageable.

Related Articles:

Configure Single Sign-On (SSO) for ArgoCD using OKTA

Reference:

Nginx Official Page

Prasad Hole

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap