What Certbot needs before it can issue a certificate
Certbot is a free client from the EFF that asks Let's Encrypt for a certificate, proves you control the domain, edits your Nginx configuration to use it and renews it on a schedule. Most failures have nothing to do with Certbot itself. They happen because Let's Encrypt cannot reach your server over plain HTTP, so check these four things first:
- DNS points at this server. Every name you request (
example.inandwww.example.in) has an A record with the VPS's public IPv4 address, and any AAAA record points at this VPS too. - Port 80 is open from the internet. The default HTTP-01 challenge works only on port 80. Let's Encrypt's documentation says the ACME standard does not allow clients to choose another port.
- Nginx has a server block for the name. The Nginx plugin finds the block to edit by its
server_nameline. - Nothing blocks Let's Encrypt. No CAA record that leaves Let's Encrypt out, and no rate limit hit by repeated failed attempts.
The steps below check each of these in order, then install Certbot and request the certificate. Commands are for Ubuntu 24.04 and 22.04 with Nginx installed from the Ubuntu archive; run them as a user with sudo.
Step 1: check DNS, including AAAA records
Find the server's public addresses, then compare them with what DNS returns for each name:
curl -4 https://ifconfig.co
curl -6 https://ifconfig.co
dig +short A example.in
dig +short A www.example.in
dig +short AAAA example.in
dig +short AAAA www.example.in
The A answers must match the first line. AAAA records need more care than most people give them. Let's Encrypt's IPv6 documentation says that when a name has both A and AAAA records, validation always tries the IPv6 address first, and it falls back to IPv4 only if the IPv6 connection times out. If an old AAAA record points at a previous host, or the VPS answers on IPv6 but Nginx is not serving the site there, validation fails even though the site loads over IPv4. There is no way to ask Let's Encrypt to prefer IPv4: either make IPv6 work or delete the AAAA record.
From a Windows PC, the same checks are:
nslookup -type=A example.in 1.1.1.1
nslookup -type=AAAA example.in 1.1.1.1
If DNS is not set up yet, our guide on pointing a domain to a VPS covers the records, TTLs and parking pages.
Step 2: open ports 80 and 443
There are usually two firewalls: ufw on the server and a network firewall at your provider. Check the one on the server first:
sudo ufw status verbose
sudo ufw allow 'Nginx Full'
Nginx Full is the ufw application profile for ports 80 and 443. If ufw shows as inactive and you decide to turn it on, run sudo ufw allow OpenSSH before sudo ufw enable, or you will cut off your own SSH session.
Then test from outside the server, because a rule that looks right on the VPS can still be blocked upstream. From another Linux machine, or from Windows PowerShell:
# Linux or macOS
curl -I http://example.in/
# Windows PowerShell
Test-NetConnection example.in -Port 80
curl.exe -I http://example.in/
A TcpTestSucceeded : True line or any HTTP status line (even a 404) means port 80 is reachable. A timeout means a firewall is dropping the traffic. Keep port 80 open after the certificate is issued: renewals use the same challenge.
Step 3: give Nginx a server block for the domain
Certbot's Nginx plugin edits an existing server block, so create a plain HTTP block first. Save this as /etc/nginx/sites-available/example.in:
server {
listen 80;
listen [::]:80;
server_name example.in www.example.in;
root /var/www/example.in;
index index.html;
}
Enable it, test the syntax and reload:
sudo mkdir -p /var/www/example.in
sudo ln -s /etc/nginx/sites-available/example.in /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
Every name you will pass to Certbot with -d must appear in server_name. If you are new to how Nginx picks a server block, read what Nginx is and how it works first.
Step 4: install Certbot on Ubuntu 24.04 or 22.04
The Certbot project strongly recommends the snap for most users; it follows current Certbot releases instead of the version frozen in the Ubuntu archive. Its instructions first remove any copy installed with apt (if none is installed, apt just says so), so that the certbot command runs the snap:
sudo apt remove certbot
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/local/bin/certbot
certbot --version
You can also install from the Ubuntu archive with sudo apt install certbot python3-certbot-nginx. That works, but the version stays fixed for the life of the release: Ubuntu 24.04 ships Certbot 2.9.0. The version matters for renewal timing, covered in Step 6. Use one method, not both.
Step 5: request the certificate with the Nginx plugin
With DNS, ports and the server block in place, one command does the rest:
sudo certbot --nginx -d example.in -d www.example.in
On the first run Certbot asks for an email address and for you to accept the Let's Encrypt subscriber agreement. It then:
- asks Let's Encrypt for a certificate covering both names;
- serves a token for each name at
http://example.in/.well-known/acme-challenge/<token>, which Let's Encrypt fetches over port 80; - saves the key and certificate under
/etc/letsencrypt/live/example.in/; - adds
listen 443 ssl,ssl_certificateandssl_certificate_keylines to your server block and, by default, a redirect from HTTP to HTTPS (add--no-redirectto skip it); - reloads Nginx.
Open https://example.in/ to confirm. Put both the bare name and www in one certificate; requesting only one is a common reason the other name later shows a certificate error. If Certbot's edit breaks something, sudo certbot --nginx rollback reverts its configuration changes.
The files Certbot creates
| File | What it is | Nginx directive |
|---|---|---|
fullchain.pem | Your certificate followed by the intermediate certificates | ssl_certificate |
privkey.pem | The private key; keep it secret and never share it | ssl_certificate_key |
cert.pem, chain.pem | The certificate alone and the intermediates alone | Not needed for Nginx |
Point configuration at these paths rather than copying the files. The Certbot user guide notes that /etc/letsencrypt/live is updated on every renewal, so a copy would go stale.
If you prefer to edit Nginx yourself
sudo certbot certonly --nginx -d example.in -d www.example.in gets the certificate but leaves the configuration alone. Add listen 443 ssl;, ssl_certificate and ssl_certificate_key to the server block by hand, then run sudo nginx -t and reload. Certbot still renews the certificate automatically; add a deploy hook (below) so Nginx picks up each renewed certificate.
Step 6: make sure renewal works
Let's Encrypt certificates currently last 90 days by default, so renewal must be automatic. Both the snap and the apt package install a timer or cron job that runs certbot renew. Test it now, not in three months:
sudo certbot renew --dry-run
systemctl list-timers | grep -i certbot
sudo certbot certificates
--dry-run goes through a full renewal against the Let's Encrypt staging server, so it does not use up real issuance limits. certbot certificates lists each certificate's names, expiry date and file paths.
When does Certbot actually renew? From Certbot 4.0, a certificate is due when less than a third of its lifetime remains; earlier versions, including the 2.9.0 package in Ubuntu 24.04, use a fixed 30 days before expiry. That difference is starting to matter. Let's Encrypt has announced that its default certificates move to 64 days on 10 February 2027 and to 45 days on 16 February 2028, and it recommends clients that support ACME Renewal Information (ARI). A current snap install is the simplest way to stay ahead of those changes.
Do not rely on email reminders: Let's Encrypt stopped sending expiry notification emails on 4 June 2025. If you want an alert, monitor the certificate's expiry date from outside, or watch the renewal logs in /var/log/letsencrypt/.
Reload Nginx after renewal with a deploy hook
If you used certonly, or another service uses the same certificate, put an executable script in Certbot's deploy hook folder. Deploy hooks run only after a certificate was actually renewed:
sudo tee /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh >/dev/null <<'EOF'
#!/bin/sh
systemctl reload nginx
EOF
sudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh
Quick diagnosis: Certbot errors and what they mean
When issuance fails, Certbot prints the problem Let's Encrypt reported for each name. Match the key phrase:
| Error contains | What it means | Fix |
|---|---|---|
Timeout during connect (likely firewall problem) | Let's Encrypt could not open a connection to port 80 | Open port 80 in ufw and in the provider firewall; check the AAAA record |
Connection refused | The packet reached the server but nothing listens on port 80 at that address | Start Nginx; add listen [::]:80; if the name has an AAAA record |
Invalid response from ... 404 | A web server answered, but not with the challenge file | DNS points at another server, another server block caught the request, or a rule blocks /.well-known/ |
DNS problem: NXDOMAIN looking up A | The name does not exist in DNS | Create the record at your DNS host; check for typos in -d |
CAA record for ... prevents issuance | A CAA record allows other CAs but not Let's Encrypt | Add 0 issue "letsencrypt.org" or remove the CAA record |
too many certificates or too many failed authorizations | A rate limit was hit | Wait for the window to refill; test with --dry-run first |
Could not automatically find a matching server block | No Nginx block lists that name in server_name | Add the name to server_name, run nginx -t, reload, retry |
nginx: [emerg] after running Certbot | The Nginx configuration has an error | Run sudo nginx -t and fix the file and line it names |
Timeout versus connection refused
These two look similar but point to different places. A timeout means the packets were dropped on the way, almost always by a firewall. A dead IPv6 address can also cause it: Let's Encrypt retries over IPv4 after an IPv6 timeout, but only on the first request, not after a redirect. "Connection refused" means the server answered that nothing listens on port 80, which points to Nginx being stopped or listening only on IPv4. Check with sudo ss -tlnp | grep ':80' on the server.
Invalid response and 404
Create a test file and fetch it from outside:
sudo mkdir -p /var/www/example.in/.well-known/acme-challenge
echo ok | sudo tee /var/www/example.in/.well-known/acme-challenge/test
curl -iL http://example.in/.well-known/acme-challenge/test
If you do not get ok back, the request is not reaching this server block. Typical causes are an old A or AAAA record, a CDN proxy in front of the site, or another server block catching the name. A location ~ /\. rule that denies every hidden path also blocks this test file and the webroot method, although the Nginx plugin adds its own exact-match location for the real token. Let's Encrypt follows up to 10 redirects during this check, but only to ports 80 and 443, so an HTTP-to-HTTPS redirect is fine. Delete the test file afterwards with sudo rm /var/www/example.in/.well-known/acme-challenge/test.
Rate limits
Let's Encrypt allows up to 5 certificates for the exact same set of names every 7 days, 50 certificates per registered domain every 7 days, and 5 failed validations per name per account per hour. Running the same failing command in a loop is how most people hit the last one. Fix the cause using the steps above, test with --dry-run, then make one real attempt.
Wildcard certificates and blocked port 80
The HTTP-01 challenge cannot issue a wildcard such as *.example.in, and it cannot work if port 80 is unavailable. For those cases, Let's Encrypt offers the DNS-01 challenge: your client puts a TXT record at _acme-challenge.example.in and Let's Encrypt checks it in DNS. With Certbot that means a DNS plugin for your provider (on a snap install, Certbot's instructions first run sudo snap set certbot trust-plugin-with-root=ok, then for example sudo snap install certbot-dns-cloudflare) and an API credential stored on the server. It is more setup, so use it only when you need a wildcard or cannot open port 80.
Common mistakes
- Running Certbot before DNS has updated. Check with
digagainst a public resolver first; each failed run counts towards the hourly limit. - Forgetting the AAAA record. IPv4 works in your browser, but validation still fails over IPv6.
- Closing port 80 after issuance. The next renewal uses port 80 again and fails quietly until the certificate expires.
- Requesting only
wwwor only the bare name. The other one then shows a certificate name mismatch. - Installing Certbot twice. An apt copy and a snap copy can leave two renewal jobs and confusion over which
certbotruns. - Copying the .pem files elsewhere. The copies do not update on renewal; point Nginx at
/etc/letsencrypt/live/. - Testing against production repeatedly. Use
--dry-runor--test-certwhile you debug. - Turning on a CDN proxy before the certificate exists. With Cloudflare, issue the certificate with the record set to DNS only, then switch the proxy on with SSL mode Full (strict).
If the certificate has already expired and visitors see a warning, our guide to NET::ERR_CERT_DATE_INVALID covers recovery.
Sources (checked )
- EFF (Certbot): Certbot instructions: Nginx on Linux (snap)
- EFF (Certbot): Certbot User Guide
- Let's Encrypt: Challenge Types
- Let's Encrypt: IPv6 Support
- Let's Encrypt: Rate Limits
- Let's Encrypt: Certification Authority Authorization (CAA)
- Let's Encrypt: Decreasing Certificate Lifetimes to 45 Days
- Let's Encrypt: Ending Support for Expiration Notification Emails
- Ubuntu (Canonical): Package certbot in noble (24.04 LTS)