Talk to the NOC, IST hours — +91 75994 50220 support@bigdomainhost.com
Guide

How to install a free Let's Encrypt SSL certificate on Nginx with Certbot

A VPS gives you full control of HTTPS, which also means setting it up yourself. This guide checks the four things Let's Encrypt needs before you run anything, installs Certbot on Ubuntu 24.04 or 22.04, issues and renews the certificate, and explains each error Certbot can print, from firewall timeouts to rate limits.

Short answer: To install a free SSL certificate on Nginx, point the domain's A record at your VPS, open ports 80 and 443, list the domain in an Nginx server_name, install Certbot with sudo snap install --classic certbot, and run sudo certbot --nginx -d example.in -d www.example.in. Certbot renews it automatically; test that with sudo certbot renew --dry-run.

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:

  1. DNS points at this server. Every name you request (example.in and www.example.in) has an A record with the VPS's public IPv4 address, and any AAAA record points at this VPS too.
  2. 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.
  3. Nginx has a server block for the name. The Nginx plugin finds the block to edit by its server_name line.
  4. 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:

  1. asks Let's Encrypt for a certificate covering both names;
  2. serves a token for each name at http://example.in/.well-known/acme-challenge/<token>, which Let's Encrypt fetches over port 80;
  3. saves the key and certificate under /etc/letsencrypt/live/example.in/;
  4. adds listen 443 ssl, ssl_certificate and ssl_certificate_key lines to your server block and, by default, a redirect from HTTP to HTTPS (add --no-redirect to skip it);
  5. 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

Files in /etc/letsencrypt/live/example.in/
FileWhat it isNginx directive
fullchain.pemYour certificate followed by the intermediate certificatesssl_certificate
privkey.pemThe private key; keep it secret and never share itssl_certificate_key
cert.pem, chain.pemThe certificate alone and the intermediates aloneNot 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:

Common Certbot and Let's Encrypt errors on Nginx
Error containsWhat it meansFix
Timeout during connect (likely firewall problem)Let's Encrypt could not open a connection to port 80Open port 80 in ufw and in the provider firewall; check the AAAA record
Connection refusedThe packet reached the server but nothing listens on port 80 at that addressStart Nginx; add listen [::]:80; if the name has an AAAA record
Invalid response from ... 404A web server answered, but not with the challenge fileDNS points at another server, another server block caught the request, or a rule blocks /.well-known/
DNS problem: NXDOMAIN looking up AThe name does not exist in DNSCreate the record at your DNS host; check for typos in -d
CAA record for ... prevents issuanceA CAA record allows other CAs but not Let's EncryptAdd 0 issue "letsencrypt.org" or remove the CAA record
too many certificates or too many failed authorizationsA rate limit was hitWait for the window to refill; test with --dry-run first
Could not automatically find a matching server blockNo Nginx block lists that name in server_nameAdd the name to server_name, run nginx -t, reload, retry
nginx: [emerg] after running CertbotThe Nginx configuration has an errorRun 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 dig against 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 www or 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 certbot runs.
  • Copying the .pem files elsewhere. The copies do not update on renewal; point Nginx at /etc/letsencrypt/live/.
  • Testing against production repeatedly. Use --dry-run or --test-cert while 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 )

Answers

Frequently asked questions

Still unsure? Call +91 75994 50220 or write to support@bigdomainhost.com — a human replies in IST hours.

Is a Let's Encrypt certificate really free?

Yes. Let's Encrypt issues domain-validated certificates at no cost, and Certbot is free, open-source software from the EFF. The encryption is the same as a paid DV certificate. What you give up is organisation or extended validation and a CA warranty, which most websites do not need.

How do I renew a Let's Encrypt certificate with Certbot?

You normally do not need to: the snap and the apt package both install a timer or cron job that runs certbot renew automatically. To check it works, run sudo certbot renew --dry-run, which tests renewal against the Let's Encrypt staging server. sudo certbot certificates shows each certificate's expiry date.

How long is a Let's Encrypt certificate valid?

Default certificates are valid for 90 days. Let's Encrypt has announced that the default moves to 64 days on 10 February 2027 and to 45 days on 16 February 2028, so automatic renewal with a current Certbot matters more each year.

Should I install Certbot with snap or apt on Ubuntu?

The Certbot project recommends the snap because it tracks the current release. The apt package works but stays on the version shipped with your Ubuntu release, 2.9.0 on Ubuntu 24.04. Versions before 4.0 renew at a fixed 30 days before expiry instead of when a third of the lifetime remains. Pick one method only.

Why does Certbot say Timeout during connect (likely firewall problem)?

Let's Encrypt could not open a connection to port 80 on your server. Open port 80 in ufw and in any firewall your provider runs, then test from another network with curl -I http://yourdomain/. If the name has an AAAA record, check that IPv6 reaches the server too, because Let's Encrypt tries IPv6 first.

Can I get a Let's Encrypt certificate without opening port 80?

Yes, with the DNS-01 challenge, where your ACME client proves control by creating a TXT record at _acme-challenge under your domain. With Certbot it needs a DNS plugin for your DNS provider and an API credential. DNS-01 is also the only way to get a wildcard certificate from Let's Encrypt.

Does Certbot set up the HTTP to HTTPS redirect?

Yes. When you run certbot --nginx, it adds a redirect from HTTP to HTTPS by default. Add --no-redirect if you want to keep plain HTTP working, or use certbot certonly --nginx to get the certificate without any change to your Nginx files.

Where does Certbot store the certificate files?

In /etc/letsencrypt/live/yourdomain/. Nginx needs fullchain.pem for ssl_certificate and privkey.pem for ssl_certificate_key. Point your configuration at these paths instead of copying the files, because Certbot updates them on every renewal.

Support that picks up the phone.

In IST hours, in Hindi or English, and WhatsApp replies fastest at any time. Sales, migration and emergencies all reach the same engineers. No offshore queue, no 48-hour first reply.

Need cPanel or WHM with the ports already sorted?

Web & cPanel hosting comes with cPanel ready to log in to, reseller hosting adds white-label WHM, and a KVM VPS can have cPanel & WHM pre-installed. Call +91 75994 50220 or email support@bigdomainhost.com.