How to Set Up SSL on Ubuntu 22.04 with Nginx and Let’s Encrypt

To set up SSL on your Ubuntu 22.04 server, you can use Let’s Encrypt, a free SSL certificate provider. Here’s a step-by-step guide on how to do it:


Step 1: Install Nginx (if not already installed)

Make sure you have Nginx installed. If not, follow these steps:

sudo apt update
sudo apt install nginx -y

Step 2: Install Certbot and Nginx Plugin

Certbot is the recommended tool for obtaining and renewing Let’s Encrypt SSL certificates.

  1. Add the Certbot repository and install the required packages:
    sudo apt install certbot python3-certbot-nginx -y

Step 3: Obtain an SSL Certificate

  1. Ensure that your domain is correctly pointed to your server’s IP address.
  2. Run Certbot to automatically configure SSL with Nginx:
    sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

    Replace yourdomain.com with your actual domain name.

  3. Certbot will ask you to provide an email address and agree to the terms of service. After that, it will automatically configure SSL for your Nginx server.

Step 4: Verify SSL Installation

After the process is complete, you should see a success message. Certbot will automatically reload Nginx, and SSL will be active.

To verify the SSL installation, open your website in a browser using https://. You should see the padlock icon next to the URL, indicating a secure connection.

Alternatively, you can use tools like SSL Labs’ SSL Test to check the configuration.

Step 5: Set Up Auto-Renewal

Let’s Encrypt certificates are valid for 90 days, so you need to set up auto-renewal to ensure your SSL certificate doesn’t expire.

  1. Certbot automatically sets up a cron job for auto-renewal, but you can test it manually to make sure it works:
    sudo certbot renew --dry-run

    If the test passes, Certbot will renew your certificates automatically.

Step 6: Force HTTPS (Optional)

To ensure your visitors always access your site over HTTPS, you can configure Nginx to redirect HTTP to HTTPS.

  1. Open your Nginx configuration file for your site:
    sudo nano /etc/nginx/sites-available/yourdomain.com
  2. Add the following configuration inside the server block to force the redirect:
    server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    return 301 https://$host$request_uri;
    }
  3. Save and close the file. Then, test and reload Nginx:
    sudo nginx -t
    sudo systemctl reload nginx

Step 7: Check and Test SSL

  1. Visit your website using https:// and confirm that the padlock icon appears in the browser’s address bar, indicating a secure connection.
  2. You can also check your SSL certificate using online tools like SSL Labs’ SSL Test.

Now, your site should be securely running on HTTPS with a free SSL certificate from Let’s Encrypt. Let me know if you need further assistance!

Download Now No episodes found.Posted in UbuntuTagged , , , , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *