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.
| Part | Job |
|---|---|
| Domain registrar | Sells the domain and hosts its DNS settings |
| DNS A record | Points the domain to your server |
| Let's Encrypt | Checks you control the domain and issues the certificate |
| Certbot | Runs the check, saves the files and renews them |
| NGINX | Presents the certificate, encrypts traffic and forwards requests |
| Your app | Receives 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:
- The registrar (Namecheap). You buy your domain here. Namecheap acts as the land registry holding the deed to your domain name.
- 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.
- The reverse proxy (NGINX). NGINX stands guard at the front door of your server on Port 80 (HTTP) and Port 443 (HTTPS).
- 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.
- User
- DNSA record
- Server IP
- NGINX:80 / :443
- 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:
sudo certbot --nginx -d example.com -d www.example.comCertbot does not decide whether you own the domain. Let's Encrypt does, using a challenge. The most common one is HTTP-01:
- Let's Encrypt gives Certbot a token.
- Certbot makes a file with that token available on your server, at
http://example.com/.well-known/acme-challenge/<token>. - Let's Encrypt fetches that address over port 80, from several locations.
- 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:
- The browser connects to port 443 (HTTPS).
- NGINX sends the certificate in
fullchain.pem. - The browser checks that it is valid, matches the domain and was issued by an authority it trusts.
- NGINX proves it holds the private key, without sending it.
- 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:
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:
sudo certbot renew --dry-run # test a renewal without changing anything
systemctl list-timers | grep certbotSince 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.comwith 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.comrequires 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.