Install Let's Encrypt SSL on Nginx with Certbot — Step by Step

Install Certbot Let's Encrypt SSL on Nginx VPS

Table of Contents

  1. What is Let's Encrypt and Certbot?
  2. Prerequisites
  3. Install Certbot on Ubuntu
  4. Obtain an SSL Certificate
  5. Configure Nginx for HTTPS
  6. Set Up Automatic Renewal
  7. Verify SSL — Achieving Grade A
  8. Troubleshooting Common Issues
  9. Frequently Asked Questions
  10. Conclusion

What is Let's Encrypt and Certbot?

Let's Encrypt is a free, automated, and open Certificate Authority (CA) operated by the Internet Security Research Group (ISRG). It issues Domain Validated (DV) SSL certificates at no cost, backed by Mozilla, Google, Cisco, and other technology leaders.

Certbot is an ACME protocol client developed by the Electronic Frontier Foundation (EFF) that automates the process of obtaining and renewing Let's Encrypt certificates. It has native plugins for Nginx and Apache.

Benefits of Let's Encrypt: 100% free · Automatic renewal · Wildcard support · Trusted by all major browsers · Issued in under 2 seconds

Prerequisites

Before installing Certbot, ensure the following are in place:

RequirementDetailsStatus
Ubuntu VPSUbuntu 20.04 / 22.04 / 24.04✅ Required
Nginx installedVersion 1.18+ recommended✅ Required
Domain pointing to VPSA Record → VPS IP address✅ Required
Ports 80 and 443 openCertbot uses HTTP challenge✅ Required
Root or sudo accessRequired for package installation✅ Required

Verify Nginx is running:

sudo systemctl status nginx
# Should show: Active: active (running)

Install Certbot on Ubuntu

Installing via snap is recommended as it always provides the latest version with automatic updates:

# Update package list
sudo apt update

# Install snapd (pre-installed on Ubuntu 20.04+)
sudo apt install -y snapd

# Update snap core
sudo snap install core
sudo snap refresh core

# Install certbot via snap
sudo snap install --classic certbot

# Create symlink
sudo ln -s /snap/bin/certbot /usr/bin/certbot

# Verify installation
certbot --version
⚠️ Note: If you previously installed certbot via apt, remove it first: sudo apt remove certbot

Obtain an SSL Certificate

Certbot's Nginx plugin handles everything automatically — certificate issuance and Nginx configuration:

# Issue certificate and configure Nginx automatically
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

# Or obtain certificate only, without modifying Nginx config
sudo certbot certonly --nginx -d yourdomain.com -d www.yourdomain.com

Certbot will prompt for your email address and ask you to agree to the Terms of Service. Certificates are stored at:

/etc/letsencrypt/live/yourdomain.com/fullchain.pem  # Certificate
/etc/letsencrypt/live/yourdomain.com/privkey.pem     # Private Key

Obtaining a Wildcard SSL Certificate

Wildcard SSL covers all subdomains (*.yourdomain.com) and requires a DNS Challenge:

sudo certbot certonly --manual --preferred-challenges dns \
  -d "yourdomain.com" -d "*.yourdomain.com"

Certbot will ask you to add a TXT record to your DNS. After DNS propagates, press Enter to continue.

Configure Nginx for HTTPS

When using the --nginx flag, Certbot modifies your config automatically. For manual setup, use this template:

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name yourdomain.com www.yourdomain.com;

    ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    root /var/www/yourdomain.com;
    index index.html index.php;

    location / {
        try_files $uri $uri/ =404;
    }
}
# Test configuration
sudo nginx -t

# Reload Nginx
sudo systemctl reload nginx

Enabling HSTS (Recommended)

HSTS forces browsers to always use HTTPS, adding an extra layer of security:

# Inside the 443 server block
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

Set Up Automatic Renewal

Let's Encrypt certificates are valid for 90 days. When installed via snap, Certbot automatically sets up a systemd timer or cron job for renewal.

# Check the renewal timer
sudo systemctl list-timers | grep certbot

# Or check cron
sudo crontab -l | grep certbot

Test renewal without actually issuing a certificate (dry run):

sudo certbot renew --dry-run
# Should show: Congratulations, all simulated renewals succeeded
✅ Certbot renews automatically when less than 30 days remain. No manual action needed every 90 days.

Verify SSL — Achieving Grade A

After installation, verify your SSL configuration with these tools:

# View issued certificates
sudo certbot certificates

# Output shows domain, expiry date, and certificate path

Troubleshooting Common Issues

1. Error: Connection Refused / Port 80 Blocked

# Open ports 80 and 443 in UFW
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload

2. DNS Problem / Domain Not Resolving

The domain's A Record may not be pointing to the VPS IP, or DNS hasn't propagated. Wait 24–48 hours after changing DNS.

# Check DNS propagation
dig yourdomain.com A +short
# Should return your VPS IP address

3. Certificate Renewal Failure

# Check logs
sudo journalctl -u snap.certbot.renew --since "1 day ago"

# Or view certbot log directly
sudo tail -50 /var/log/letsencrypt/letsencrypt.log

4. Nginx: SSL_CTX_use_PrivateKey_file Failed

The certificate and private key don't match. Force-renew the certificate:

sudo certbot renew --force-renewal -d yourdomain.com

Frequently Asked Questions

Is Let's Encrypt really free? Are there hidden costs?

100% free with no hidden costs. Let's Encrypt is a non-profit supported by Mozilla, Google, Cisco, and EFF. Certificate issuance and renewal are always free.

How does Let's Encrypt compare to paid SSL certificates?

Let's Encrypt issues DV (Domain Validated) SSL, suitable for blogs and general websites. Paid SSL comes in DV, OV (Organization Validated), and EV (Extended Validation) — higher tiers provide organizational identity verification, important for enterprise and e-commerce sites.

What should I do if my certificate has already expired?

Run sudo certbot renew --force-renewal followed by sudo systemctl reload nginx. If auto-renewal was configured correctly, Certbot should have renewed before expiry.

Can I use Let's Encrypt on an AsiaGB VPS?

Yes. AsiaGB VPS (Thailand and Singapore) fully supports Let's Encrypt. Simply point your domain's A Record to your VPS IP and follow the steps in this guide.

Which Ubuntu versions does Certbot support?

Certbot supports Ubuntu 20.04, 22.04, and 24.04 LTS. Installing via snap is recommended for the latest version and automatic updates.

What are Let's Encrypt's rate limits?

50 certificates per registered domain per week, and 5 duplicate certificates per hour. These limits are rarely encountered in normal usage.

Conclusion

Installing Let's Encrypt SSL with Certbot on Nginx VPS takes just 5–10 minutes with a handful of commands. The critical step is configuring auto-renewal correctly so your certificate never expires unexpectedly.

Need an OV or EV SSL certificate for a business site requiring organizational validation? AsiaGB offers multiple SSL certificate types with professional installation support.

View AsiaGB VPS Plans