guest@websec ~ % man s03-lets-encrypt-ssl
Let's Encrypt SSL Certificates
Issue free, automated TLS certificates on Ubuntu 24.04 using Certbot — separated into single-domain requests (HTTP-01) and wildcard requests (*.example.com via DNS-01).
snap so Ubuntu's systemd timer auto-renews certificates before their 90-day expiry. Use Section 1 (HTTP-01, port 80) for a single host like api.example.com, and Section 2 (DNS-01 API plugin) for wildcards (-d example.com -d "*.example.com") so renewals run unattended. Always verify with sudo certbot renew --dry-run.Shared setup: 1 domain vs wildcard & installing Certbot
Let's Encrypt is a free, automated Certificate Authority (CA) speaking the ACME protocol. Before issuing a certificate, Let's Encrypt demands proof that you really control the domain. Which proof it accepts depends on whether you ask for a specific hostname or a wildcard:
| feature | Section 1 · Single Domain | Section 2 · Wildcard (*.example.com) |
|---|---|---|
| Covers | Exact host(s) listed, e.g. api.example.com (or example.com + www.example.com) | Every one-level subdomain (api., admin., cdn.) + bare example.com if requested together |
| ACME challenge | HTTP-01 — Let's Encrypt fetches a token file over http://<domain>:80/.well-known/acme-challenge/… | DNS-01 — Let's Encrypt queries a TXT record at _acme-challenge.example.com |
| Port 80 open? | required must reach this server from the internet | not needed works even on internal/VPN-only servers |
| Auto-renewal | Automatic out of the box with --nginx or --webroot | Automatic only with a DNS API plugin; --manual cannot auto-renew |
| Best for | 1–3 public servers where DNS points straight to the box | Many subdomains, multi-tenant apps, or internal servers behind a firewall |
Install Certbot once (Ubuntu 24.04)
The Certbot team recommends the official snap package over Ubuntu's older apt package so ACME protocol updates and DNS plugins stay current:
Section 1 · Single-Domain Request (HTTP-01)
Use this when you have a server running Nginx (or Caddy/Apache) and a DNS A / AAAA record pointing a hostname like api.example.com straight to that server's public IP.
1.1 How HTTP-01 validation works
1.2 Step-by-step commands (1 domain)
Before running Certbot, verify two things: DNS resolves to your server IP, and ufw (plus your cloud security group) allows both port 80 and 443.
1.3 Variations: multiple explicit names, webroot, or standalone
# Cover bare domain + www on one HTTP-01 cert (both A records must point to this server) sudo certbot --nginx -d example.com -d www.example.com # Keep Nginx untouched (certonly --webroot): you write the Nginx ssl config yourself sudo certbot certonly --webroot -w /var/www/html -d api.example.com \ --deploy-hook "systemctl reload nginx" # No web server installed yet: Certbot spins up a temporary listener on port 80 sudo certbot certonly --standalone -d api.example.com
Section 2 · Wildcard Certificate Request (DNS-01)
A wildcard certificate (*.example.com) secures every one-level subdomain — api.example.com, admin.example.com, staging.example.com — with a single certificate. Let's Encrypt refuses HTTP-01 for wildcards because proving you run one web server doesn't prove you own the entire DNS zone. You must use a DNS-01 challenge instead.
1.
*.example.com does not cover bare example.com! Almost always pass both: -d example.com -d "*.example.com" (wrap "*.example.com" in quotes so your shell doesn't expand *).2. The
* matches only one dot level: it covers api.example.com, never v1.api.example.com.2.1 How DNS-01 validation works
2.2 Production method: Automated DNS plugin (Cloudflare example)
Because Let's Encrypt certificates expire every 90 days, production wildcards should use a DNS plugin (available for Cloudflare, AWS Route 53, DigitalOcean, Google Cloud DNS, Porkbun, etc.) with a narrowly scoped API token so Certbot can create and delete the _acme-challenge TXT record unattended:
2.3 Manual method: Any DNS provider without an API
If your domain registrar has no DNS API, you can pass --manual --preferred-challenges dns and paste the TXT record into your DNS web panel yourself. Always verify propagation in a second terminal before pressing Enter:
2.4 Wiring a wildcard certificate into Nginx
Because Section 2 used certonly, point your Nginx server blocks at fullchain.pem and privkey.pem once — every subdomain can share the exact same two lines:
server {
listen 80;
server_name example.com *.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name api.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
}Always test the syntax before reloading: sudo nginx -t && sudo systemctl reload nginx.
What lives inside /etc/letsencrypt/
Click each path to see what Certbot creates and which files your web server actually uses:
Common pitfalls & rate limits
- Hitting the 5-per-week duplicate cert limit while debugging: Add
--staging(or--dry-run) whenever testing scripts or Docker entrypoints. Once everything succeeds, run once without--staging. - Closing port 80 after getting an HTTP-01 cert: Around day 60,
snap.certbot.renew.timerruns HTTP-01 over port 80 again. If you blocked port 80 inufwor AWS Security Groups, silent renewal fails and your site goes down on day 90. - Cloudflare orange-cloud proxy loop: If Cloudflare SSL mode is set to "Flexible" (Cloudflare → HTTP → your server) and your Nginx redirects HTTP → HTTPS, visitors get an infinite redirect loop. Set Cloudflare SSL/TLS to Full (strict) once Let's Encrypt is installed.
- Revoking vs deleting: Rebuilding a server? Only run
certbot revokeifprivkey.pemwas leaked. Deleting a VM without revoking is normal (just back up/etc/letsencryptif rebuilding the same domain repeatedly so you don't burn rate limits).
Check yourself
You want one Let's Encrypt certificate that works for example.com, api.example.com, and admin.example.com, plus any new one-level subdomain you add next month. How should you request it?
Wildcards require DNS-01 (never HTTP-01), *.example.com does not cover bare example.com unless both -d flags are included, and a DNS API plugin lets renewals succeed automatically.
HTTPS works in Chrome on your laptop, but teammates report curl https://api.example.com and mobile apps fail with SSL certificate problem: unable to get local issuer certificate. Which Nginx mistake causes this?
cert.pem omits the intermediate CA certificate; desktop browsers often paper over this by fetching intermediates on the fly, whereas curl, mobile SDKs, and backend HTTP clients reject incomplete chains. Always use fullchain.pem.
You issued a wildcard certificate using certbot certonly --manual --preferred-challenges dns and pasted the TXT record in your registrar's web UI. What happens 60–90 days later?
Every renewal requires a fresh ACME challenge token. Without a DNS API plugin (or --manual-auth-hook script), Certbot cannot update your DNS TXT records unattended.