Let's Encrypt with Nginx

This guide explains how to install a free Let's Encrypt SSL certificate on a Linux server running Nginx using Certbot — including automatic renewal.

Prerequisites: Nginx must be installed and running. The A record of your domain must point to your server's IP. Ports 80 and 443 must be open in the firewall.

Step 1: Install Certbot

Install Certbot and the Nginx plugin via the package manager.

Debian / Ubuntu

Terminal
apt update apt install certbot python3-certbot-nginx

CentOS / AlmaLinux / Rocky Linux

Terminal
dnf install epel-release dnf install certbot python3-certbot-nginx

Step 2: Issue the certificate

Certbot issues the certificate and configures Nginx automatically.

Replace your-domain.com with your actual domain name. Add further -d parameters for multiple domains:

Terminal
certbot --nginx -d your-domain.com -d www.your-domain.com

Certbot asks for an email address for expiry notifications and whether to redirect HTTP to HTTPS automatically. Choose 2 for the automatic redirect — this is the right choice for most websites.

Step 3: Verify the installation

Test the Nginx configuration and reload.
Terminal
nginx -t systemctl reload nginx

Open your domain in a browser — you should see https:// and the padlock icon. For a detailed check you can use SSL Labs.

Step 4: Verify automatic renewal

Let's Encrypt certificates are valid for 90 days — Certbot renews them automatically.

Certbot automatically sets up a systemd timer or cron job during installation. Check that the timer is active:

Terminal
systemctl status certbot.timer

Test the renewal process with a dry run — no real certificate is issued:

Terminal
certbot renew --dry-run

If --dry-run succeeds, automatic renewal is working correctly. No further steps needed.

Manually renew the certificate

If a manual renewal is needed.
Terminal
certbot renew systemctl reload nginx

Common error messages

ErrorCause & fix
Connection refused on port 80Port 80 is blocked by the firewall. Open it in iptables or nftables.
DNS problem: NXDOMAINThe domain's A record does not point to this server. Check DNS and wait for propagation if needed.
too many certificates already issuedLet's Encrypt allows 5 certificates per domain per week. Wait or use a staging certificate for testing.
nginx: configuration file test failedCertbot modified the Nginx config incorrectly. Check with nginx -t and fix manually if needed.

Further Documentation

The full Certbot documentation is available on the official website.