A free SSL certificate on Nginx only helps if it stays valid. Let’s Encrypt certificates last 90 days, so a certificate you install by hand and forget will expire and break your site. The fix is to set up renewal once, test it, and let the server handle the rest. This guide walks through the whole process on Ubuntu with Certbot: installing it, getting your first certificate, switching renewal on, and checking that it actually works. By the end, your site will renew its certificate on its own, and you will know how to spot trouble before visitors do.
What a self-renewing certificate actually does
A self-renewing setup has two parts. First, Certbot requests a certificate from Let’s Encrypt and configures Nginx to serve it. Second, a scheduled task runs Certbot’s renewal check twice a day. Certbot only replaces a certificate when it has less than 30 days left, so most of those checks do nothing. When a certificate does cross that line, Certbot requests a new one, installs it, and reloads Nginx. Visitors see nothing change, and the padlock stays green.
A 90-day lifetime leaves little room for forgetfulness. A paid certificate that lasts a year gives you months to notice a missed renewal email, while a free certificate gives you weeks. Automation is the whole point of using a short-lived certificate. If you are setting up HTTPS on a fresh domain, make sure the domain already points at your server before you start, as described in our guide on how to point a domain to your VPS and set up free HTTPS.
What you need before you start
You need a VPS running Ubuntu with Nginx already installed and serving your site over plain HTTP. You need a domain name whose DNS A record points at the server’s IP address, and you need to be able to run commands as root or with sudo. Check that port 80 is open in your firewall. Let’s Encrypt verifies that you control the domain by reaching your server over HTTP, so a closed port 80 stops the whole process before it starts.
Check your Nginx server block as well. Certbot’s Nginx plugin reads your server blocks to find the right one for each domain, so a broken or missing server block causes confusing errors later. If you have not created one yet, follow our walkthrough of how to set up Nginx server blocks on Ubuntu 24.04 first. Run nginx -t and fix any error it reports before you go any further.
Set up a free SSL certificate on Nginx with Certbot
Certbot is the standard tool for getting Let’s Encrypt certificates on Nginx, and the Nginx plugin handles most of the configuration for you. Install it from Ubuntu’s package repository:
sudo apt update
sudo apt install certbot python3-certbot-nginx
With Certbot installed, request a certificate for your domain. Replace example.com with your own domain, and list every name the certificate should cover:
sudo certbot --nginx -d example.com -d www.example.com
Certbot asks for an email address for expiry notices and asks whether you want to redirect all HTTP traffic to HTTPS. Say yes to the redirect. It then edits your Nginx server block to point at the new certificate files, adds the redirect, and reloads Nginx. This nginx certbot setup takes about a minute on a normal server. Open your site in a browser and check for the padlock. If you want the full step-by-step version of this first install, including the prompts Certbot shows, see our Certbot guide for installing a free Let’s Encrypt certificate on Nginx.
How Certbot auto renew works
On Ubuntu, installing Certbot also installs a systemd timer called certbot.timer, which runs certbot renew twice a day at a random time. You do not need to add a cron job yourself, and adding a second one only creates duplicate work. Check that the timer is active:
systemctl list-timers --all | grep certbot
You should see the timer listed with its next run time. If it is missing, the package install may have failed partway, and reinstalling Certbot is the fastest fix. The certbot auto renew check is cheap: it reads your certificates, skips any with more than 30 days left, and exits. When a certificate is due, Certbot contacts Let’s Encrypt, proves you still control the domain with an HTTP challenge, downloads the new certificate, and reloads Nginx so the new files take effect.
One detail catches people out. The renewal check needs port 80 open, just like the first request. If you locked down your firewall after installing the certificate, renewal will fail silently in the background. Keep port 80 open and let Nginx redirect that traffic to HTTPS. That redirect does not break the challenge, because Let’s Encrypt follows redirects to HTTPS when it checks the challenge file.
Test renewal before you trust it
A timer that has never run is a guess, not a guarantee. Test the whole renewal path with a dry run, which talks to Let’s Encrypt’s staging server instead of issuing a real certificate:
sudo certbot renew --dry-run
A passing dry run proves three things at once: the timer can run Certbot, the HTTP challenge still works, and Nginx reloads cleanly after renewal. If the dry run fails, read the error before changing anything. The most common causes are a closed port 80, a changed DNS record, or an Nginx config that no longer passes nginx -t. Fix the cause, then run the dry run again. Do not run the real certbot renew by hand to “force” a renewal. It will refuse while the certificate has more than 30 days left, and forcing it with extra flags burns through Let’s Encrypt’s rate limits for no benefit.
After a passing dry run, check what certificates Certbot is tracking and when each one expires:
sudo certbot certificates
Set a calendar reminder a week before the first renewal is due. The timer should handle it, but a reminder costs nothing and catches the one case automation cannot: a server that was offline when the timer fired.
What breaks SSL certificate renewal, and how to fix it
Renewal fails for a short list of reasons, and each one has a clear fix. The table below covers the ones you will actually meet in practice.
| Problem | Symptom | Fix |
|---|---|---|
| Port 80 closed | Dry run fails with a connection or timeout error | Open port 80 in your firewall and try again |
| DNS points elsewhere | Challenge fails with an authorization error | Point the A record back at your server and wait for DNS to propagate |
| Broken Nginx config | Certbot refuses to reload Nginx after renewal | Run nginx -t, fix the reported error, then renew |
| Certificate changed by hand | Certbot reports a mismatched or missing lineage | Delete the broken lineage and request a fresh certificate |
| Server was offline | Timer ran but renewal never happened | Run the dry run, then let the timer take over again |
Certbot sends expiry warning emails to the address you gave during setup, but only when a certificate is close to expiry and renewal has not happened. Treat that email as a real alarm, not spam. If you get one, log in, run the dry run, and find out why the timer did not do its job.
Renewal for subdomains and wildcard certificates
Subdomains follow the same process. If your certificate already covers www.example.com, adding app.example.com means requesting a new certificate that lists all three names. Certbot replaces the old certificate rather than adding to it, so always list every domain you want covered in a single command. Our guide to setting up a free SSL certificate for a subdomain on Nginx walks through that exact case, including the redirect rules that keep the subdomain working after renewal.
Wildcard certificates are the exception. A certificate for *.example.com cannot use the HTTP challenge, because there is no single web server to check. It needs a DNS challenge, where Certbot creates a TXT record through your DNS provider’s API. That means extra setup: an API token with DNS edit rights and a Certbot DNS plugin for your provider. The renewal timer still works the same way once that is in place, but the setup is harder to debug, so only use a wildcard when you genuinely add subdomains often. For most sites, one certificate listing each subdomain by name is simpler.
Keep Nginx and Certbot healthy over time
Renewal is automatic, but the server around it still needs basic care. Update Certbot with the rest of your system packages so you keep getting security fixes for the client itself. After any Nginx change, run nginx -t before reloading, because a config error that breaks a reload also breaks the next renewal. And once a quarter, run certbot renew --dry-run and certbot certificates together. Five minutes of checking every few months is the cheapest insurance against an expired certificate warning your visitors on a Sunday morning.