Logo

How to Install Let's Encrypt SSL in Nginx on Ubuntu 24.04

Mar 16, 2024

To install Let's Encrypt SSL in Nginx on Ubuntu 24.04, follow the steps below:

Step 1 : Ensure your domain has DNS records properly set up for verification.

Step 2 : Update your system:

sudo apt update

Step 3 : Install Certbot and python3-certbot-nginx:

sudo apt install certbot python3-certbot-nginx

Step 4 : Create a Nginx configuration file (example.devtutorial.io) and add the necessary configuration:

sudo nano /etc/nginx/sites-available/example.devtutorial.io

Add the configuration for your domain. Example:

server {
    listen 80;
    server_name example.devtutorial.io;
    root /var/www/example.devtutorial.io;
    index index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
}

Step 5 : Create a directory for your domain and a test HTML file:

sudo mkdir -p /var/www/example.devtutorial.io
sudo nano /var/www/example.devtutorial.io/index.html

Add some content to the HTML file, then save and close it.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Welcome to example.devtutorial.io</title>
</head>
<body>
    <h1>Welcome to example.devtutorial.io</h1>
    <p>This is a test page for verifying the Nginx configuration.</p>
</body>
</html>

Step 6 : Enable the Nginx configuration:

sudo ln -s /etc/nginx/sites-available/example.devtutorial.io /etc/nginx/sites-enabled/

Step 7 : Test the Nginx configuration:

sudo nginx -t

Step 8 : Restart Nginx:

sudo systemctl restart nginx

Step 9 : Obtain SSL certificate:

sudo certbot --nginx -d example.devtutorial.io

Follow the prompts:

- Enter your email address.

9b Agree to the terms of service.

- Share your email address with the EFF.

- Once successful, you'll receive a confirmation message.

Step 10 : Test the certificate renewal process:

sudo certbot renew --dry-run

Step 11 : Visit your domain to check the SSL installation.

Congratulations! You have successfully installed Let's Encrypt SSL in Nginx on Ubuntu 24.04.

Recommended