Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

The Short Version

On Ubuntu or Debian, with Nginx already serving the site over HTTP:

sudo apt update
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com --email YOUR_EMAIL

On the first run Certbot asks you to accept the Let's Encrypt terms. It then proves to Let's Encrypt that you control the names, adds the certificate to the matching server block, and reloads Nginx.

Before You Start

  • DNS points to this server: every name you request needs an A record, and an AAAA record if you use IPv6, that points here. Check with dig +short example.com A and dig +short example.com AAAA. Let's Encrypt prefers IPv6 when an AAAA record exists, so an old AAAA record breaks validation even when IPv4 is right.
  • Port 80 is reachable: the HTTP-01 challenge connects to port 80 from the internet. Keep it open after the switch to HTTPS too, because every renewal uses it again.
  • A server block with the names: Certbot finds the block by its server_name line.
  • A valid configuration: sudo nginx -t must report that the test is successful.

A minimal block in /etc/nginx/sites-available/example.com on Debian and Ubuntu, or /etc/nginx/conf.d/example.com.conf on AlmaLinux and Rocky Linux:

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    root /var/www/example.com;
}

Open the Firewall

With ufw on Ubuntu and Debian:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

With firewalld on AlmaLinux and Rocky Linux:

sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reload

If your provider's control panel has a firewall in front of the server, open both ports there as well.

Install Certbot on Other Systems

On AlmaLinux and Rocky Linux the packages come from the EPEL repository:

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

The Certbot project's own instructions install it as a snap on systems that have snapd:

sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/local/bin/certbot

Use one method only. If you move to the snap, remove the distribution package first (sudo apt remove certbot or sudo dnf remove certbot) so two copies do not compete.

Get the Certificate

Name every host the certificate must cover with its own -d. The first name becomes the certificate's name, and the certificate covers only the names you list. A visitor who opens a name that is missing sees a name mismatch, described in NET::ERR_CERT_COMMON_NAME_INVALID.

Current Certbot releases add an HTTP to HTTPS redirect by default and no longer ask about it. Add --no-redirect to leave port 80 serving the site as it is, or --redirect to state the default explicitly.

Certbot adds lines marked # managed by Certbot: a listen 443 ssl line, the paths /etc/letsencrypt/live/example.com/fullchain.pem and privkey.pem, and an include of /etc/letsencrypt/options-ssl-nginx.conf. Never edit or delete the files under /etc/letsencrypt by hand; Certbot manages them.

Check the Result

sudo certbot certificates
curl -I https://example.com

The first command lists each certificate with its names, expiry date, and paths. To see exactly what the server presents, use openssl s_client.

Make Sure Renewal Works

Let's Encrypt certificates are valid for 90 days today, and Let's Encrypt has announced shorter lifetimes for its default profile: 64 days from 10 February 2027 and 45 days from 16 February 2028. It no longer sends expiry reminder e-mails, so renewal must run by itself. The apt package and the snap install and start a systemd timer. Check that one is listed, and test a renewal:

systemctl list-timers | grep -i certbot
sudo certbot renew --dry-run

If no timer is listed on AlmaLinux or Rocky Linux, switch on the one the EPEL package ships with sudo systemctl enable --now certbot-renew.timer. The dry run uses the Let's Encrypt test system. Timers, hooks, and renewal failures are covered in how to renew Let's Encrypt certificates.

Common Problems

  • No matching server block: the server_name line does not contain the name you requested. Fix it, run sudo nginx -t, reload, and try again.
  • Timeout or connection refused: port 80 is closed in a firewall, or DNS points somewhere else.
  • Unauthorized or 404 on the challenge: another server answered, often through an old AAAA record.
  • Too many failed attempts: Let's Encrypt allows five failed validations per name and account each hour. Debug with --dry-run, which uses the test system, before you try for real.

Details of each run are in /var/log/letsencrypt/letsencrypt.log.

Was this answer helpful?
Loading...