Let's Encrypt with certbot on Nginx

A clean Let's Encrypt setup for Nginx: HTTP-01 for single-host certificates, DNS-01 for wildcards, and the dry-run check that confirms auto-renewal actually works before the first 89-day cliff.

Disclosure: contains an affiliate link to Inferno VPS.

Single-domain (most common path)

sudo apt update
sudo apt install -y nginx certbot python3-certbot-nginx

Make sure your Nginx server block listens on port 80 for the domain you're certifying (a placeholder HTTP-only block is fine). DNS A record must point at the server.

sudo certbot --nginx -d app.example.com \
  --email you@example.com \
  --agree-tos --no-eff-email \
  --redirect

certbot:

  1. Solves the HTTP-01 challenge over port 80.
  2. Stores the cert under /etc/letsencrypt/live/app.example.com/.
  3. Rewrites your Nginx server block to listen on 443 with TLS.
  4. Adds an HTTP→HTTPS redirect.

Multiple domains in one cert (SAN)

sudo certbot --nginx -d app.example.com -d www.app.example.com --redirect

One certificate, both names. Useful for www / apex pairs.

Wildcards via DNS-01

HTTP-01 can't issue wildcards. For *.example.com use DNS-01 with a plugin for your DNS provider:

# Cloudflare example
sudo apt install -y python3-certbot-dns-cloudflare

# API token with Zone:DNS:Edit permission
sudo mkdir -p /etc/letsencrypt
sudo nano /etc/letsencrypt/cloudflare.ini
# dns_cloudflare_api_token = YOUR_TOKEN
sudo chmod 600 /etc/letsencrypt/cloudflare.ini

sudo certbot certonly \
  --dns-cloudflare \
  --dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini \
  -d "*.example.com" -d "example.com"

Plugins exist for AWS Route 53, DigitalOcean, OVH, Hetzner DNS, and most others.

The renewal sanity check (do this now)

Let's Encrypt certs are 90 days. certbot's package installs a systemd timer that runs twice daily. Verify it works now, while context is fresh:

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

You should see "Congratulations, all simulated renewals succeeded" and an active certbot timer.

If the dry-run fails, fix it now — not in 89 days when the cert is hours from expiry.

Common renewal failure modes

"Connection refused on port 80"

certbot's HTTP-01 challenge needs port 80 reachable from the public internet. If you redirected all 80 → 443 in Nginx, certbot still needs to serve /.well-known/acme-challenge/ on port 80. The certbot-nginx plugin handles this, but custom configs sometimes break it. Keep an explicit location /.well-known/acme-challenge/ { root /var/www/html; } block in every HTTP server block.

"DNS check failed"

For DNS-01: the TXT record didn't propagate in time. Increase plugin propagation seconds, or check that the API token has the right zone permissions.

"Too many certificates already issued"

Let's Encrypt rate-limits 50 new certs per registered domain per week. Hit during testing if you blow away cert files repeatedly. Use the staging environment for tests: --staging.

"Cert renews but Nginx serves the old one"

certbot writes a deploy hook that reloads Nginx. If you removed the hook (or your distro doesn't install it), add one:

sudo nano /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh
#!/bin/sh
nginx -t && systemctl reload nginx
sudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh

OCSP stapling

Add to your Nginx server block (inside the 443 server):

ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 9.9.9.9 valid=300s;

Cuts TLS handshake latency for first-time visitors. No cost.

Strong TLS config

Replace certbot's default block with our hardened defaults (same as the n8n + Nginx guide):

ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1d;
ssl_session_tickets off;

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;

Confirm with a Mozilla Observatory or SSL Labs scan — aim for A or A+.

Common certbot mistakes

Forgot the dry-run check

Fix: run it now. sudo certbot renew --dry-run.

Tested in production and hit a rate limit

Use --staging next time. Staging certs are signed by a Let's Encrypt staging CA (browsers won't trust them, which is the point during testing).

"Renewal works but my custom server block was overwritten"

The certbot-nginx plugin tries to be helpful and edits the server block. For custom configs, use certonly mode (issue cert; do not touch Nginx) and reference the cert paths yourself.

Need a VPS for an HTTPS setup?

Any Inferno plan works. Pair certbot with the rest of the initial Ubuntu baseline and you're set.

View Inferno plans →

What to do next


Author: Ivo Pärnaste — Tallinn. Last tested: 2026-05-22 on Nginx 1.24, certbot 2.11, Ubuntu 22.04.