Abdul MoizFractional CTO · Senior EngineerBook a free call

Engineering

Demystifying Certbot, SSL, and NGINX: A Complete Guide for Full-Stack Developers

Your senior developer tells you to just run Certbot, a few files appear, and the padlock shows up. Here is what actually happens between your domain, your server, Let's Encrypt and NGINX, and what to check when it fails.

Updated · 4 min read

Fractional CTO · Senior Engineer

Key takeaways

  • Certbot proves to Let's Encrypt that you control a domain, downloads a certificate, and can configure NGINX to use it.
  • NGINX presents the certificate to visitors, encrypts the connection and passes requests to your app.
  • The private key stays on your server and never goes to the browser.

When you first deploy a custom application (like a MERN stack app) to a cloud server, dealing with domains, NGINX, and SSL certificates can feel like a black box. Your senior developer tells you to "just run Certbot," a few files magically appear, and suddenly your site has a secure padlock.

Let's demystify what is actually happening behind the scenes. By the end of this guide, you will understand how Namecheap, your server, Certbot, Let's Encrypt, and NGINX all fit together.

Who does what
PartJob
Domain registrarSells the domain and hosts its DNS settings
DNS A recordPoints the domain to your server
Let's EncryptChecks you control the domain and issues the certificate
CertbotRuns the check, saves the files and renews them
NGINXPresents the certificate, encrypts traffic and forwards requests
Your appReceives ordinary HTTP on a local port

How Certbot, SSL and NGINX fit together

Before diving into how certificates are made, it helps to understand how traffic flows into your application server:

  1. The registrar (Namecheap). You buy your domain here. Namecheap acts as the land registry holding the deed to your domain name.
  2. The DNS A record. You point your domain's A record to your cloud server's public IP address. This tells the global internet where your server lives.
  3. The reverse proxy (NGINX). NGINX stands guard at the front door of your server on Port 80 (HTTP) and Port 443 (HTTPS).
  4. The backend app (Node.js). Your backend runs safely in the background on a local port (like 3000), completely unaware of the outside world, receiving clean traffic from NGINX.
  1. User
  2. DNSA record
  3. Server IP
  4. NGINX:80 / :443
  5. Node.js:3000

How Certbot gets an SSL certificate, step by step

Step 1: Proving you control the domain

Run Certbot with your domain name:

bash
sudo certbot --nginx -d example.com -d www.example.com

Certbot does not decide whether you own the domain. Let's Encrypt does, using a challenge. The most common one is HTTP-01:

  1. Let's Encrypt gives Certbot a token.
  2. Certbot makes a file with that token available on your server, at http://example.com/.well-known/acme-challenge/<token>.
  3. Let's Encrypt fetches that address over port 80, from several locations.
  4. If the right content comes back, you have shown that you control the server the domain points to.

This is why the DNS A record matters so much. Let's Encrypt follows it. If it still points at an old server, the request goes there and the check fails.

Step 2: Downloading the certificate

Once the check passes, Let's Encrypt, a non-profit Certificate Authority, signs a certificate for your domain. Certbot saves the files under /etc/letsencrypt/live/example.com/:

fullchain.pem
The certificate, sent to every visitor
privkey.pem
The private key, which never leaves your server

Anyone may see the certificate. Nobody else should ever see the private key: whoever holds it can pretend to be your site.

Step 3: The handshake with the visitor

When someone opens your site, Certbot is not involved. NGINX takes over:

  1. The browser connects to port 443 (HTTPS).
  2. NGINX sends the certificate in fullchain.pem.
  3. The browser checks that it is valid, matches the domain and was issued by an authority it trusts.
  4. NGINX proves it holds the private key, without sending it.
  5. Both sides agree on temporary session keys for this connection.

Step 4: Encrypted traffic

From then on, everything the visitor sends is encrypted with the session keys. Someone watching the network sees only unreadable data.

NGINX decrypts each request and passes it to your app on a local port, such as 3000. The part of the configuration that does this looks like:

nginx
server {
    listen 443 ssl;
    server_name example.com www.example.com;

    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    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 $scheme;
    }
}

This is the same idea as the firewall and load balancer in a larger network: one component handles the outside world so the app behind it does not have to.


Certbot auto-renewal, and why it matters more now

Let's Encrypt certificates last 90 days by default, and that is getting shorter. The plan is 64 days from February 10, 2027 and 45 days from February 16, 2028. Renewing by hand will stop being realistic.

Most Certbot installs add a scheduled job. Check that yours works:

bash
sudo certbot renew --dry-run        # test a renewal without changing anything
systemctl list-timers | grep certbot

Since version 4.0.0, Certbot renews when less than a third of the lifetime remains. If you wrote your own schedule around a fixed 60 days, replace it.


When Certbot fails: what to check first

  • Port 80 is closed. HTTP-01 only works on port 80, even if your site only serves HTTPS. Check the server firewall and the cloud provider's rules.
  • The A record points at an old server. Compare dig +short example.com with your server's address.
  • An AAAA record exists. If it points somewhere else, the check may go there over IPv6.
  • A proxy answers first. A CDN in front of your server may intercept the request.
  • You need a wildcard. *.example.com requires the DNS-01 challenge, which adds a TXT record instead.
  • The certificate renewed but visitors see the old one. NGINX has to reload to pick up new files.

Common questions

How long does a Let's Encrypt certificate last?

Ninety days by default today. Let's Encrypt plans to change the default to 64 days on February 10, 2027 and 45 days on February 16, 2028, so automatic renewal matters more each year.

Why does Certbot fail to verify my domain?

The usual causes are port 80 being blocked, an A record pointing at an old server, an AAAA (IPv6) record pointing somewhere else, or a proxy in front of the server answering the check instead.

Does Certbot renew certificates automatically?

Most installs add a timer or scheduled job that does. Run sudo certbot renew --dry-run to confirm it works. Since version 4.0.0, Certbot renews when less than a third of the lifetime is left.

Can I get a wildcard certificate with Certbot?

Yes, but not with the HTTP check. Wildcard certificates need the DNS-01 challenge, which proves control by adding a TXT record to your DNS.

Sources and further reading

Abdul MoizFractional CTOSenior Engineer

About the author

I build production-grade AI applications, AI agents and data systems, fix AI-built apps, and help teams as a fractional CTO. I've spent seven years building software people rely on, including a media platform that grew to 2M+ users.

ShareXLinkedIn

Keep reading

Working on something like this?

Tell me about it on a free 30-minute call.