Your site needs HTTPS, and a paid certificate is not the way to get it for a single VPS. A free SSL on Nginx with Certbot setup takes about ten minutes: install Certbot, point it at your server block, and let it fetch a certificate from Let’s Encrypt, wire up the redirect, and schedule renewals for you. This guide walks through the whole thing on Ubuntu 24.04, with fixes for the errors that actually show up in practice.
Before you start, check that your domain already points at the server. Certbot proves you own the domain by asking Let’s Encrypt to fetch a file from your site over plain HTTP, so a DNS record that still points at your old host will fail the check. Run dig +short example.com and confirm the answer is your VPS IP before you go any further. If you have not pointed the domain yet, sort that out first; the guide on pointing a new domain to your VPS and setting up free HTTPS covers the DNS side step by step.
What Certbot Actually Does
Certbot is the official client for Let’s Encrypt, the certificate authority that issues free domain-validated certificates. It does three jobs: it proves you control the domain, it downloads the certificate and private key, and it edits your Nginx config to use them. The Nginx plugin also adds the HTTP to HTTPS redirect, so visitors who type the plain address land on the secure version.
Let’s Encrypt certificates last 90 days. That is a design choice, not a drawback: short lifetimes push automation, and Certbot renews in the background. The only thing you need to remember is to check that the automatic renewal actually works, which this guide covers below.
One thing Certbot cannot do is fix a broken Nginx config. If nginx -t reports an error, Certbot will refuse to touch the file, so run the test first. The walkthrough on testing a new Nginx config without taking your site down shows how to try changes safely.
What You Need Before You Start
You need a VPS running Ubuntu 22.04 or 24.04, Nginx already installed and serving the site on port 80, and a domain name with an A record pointing at the server. You also need root or sudo access. Port 80 must be open in your firewall, because the validation request arrives over plain HTTP. Port 443 needs to be open too, or nobody can reach the HTTPS version once it exists.
Check the firewall with sudo ufw status. If you see only OpenSSH allowed, add the web profile:
sudo ufw allow 'Nginx Full'
sudo ufw status
‘Nginx Full’ opens both port 80 and port 443. If you run a different firewall, open the same two ports there. A closed port 80 is the most common reason the whole process fails, and the error message Certbot prints does not always make that obvious.
Your server block also needs a server_name that matches the domain exactly. Certbot reads that line to decide which certificate to request. A block that still says server_name _; or lists the wrong domain will produce a certificate for the wrong name, or fail outright. Open your site config in /etc/nginx/sites-available/ and confirm it before continuing.
Get Free SSL on Nginx With Certbot in One Command
Install Certbot and the Nginx plugin from the Ubuntu repositories. The certbot nginx setup is a single package install, no third-party repository needed on current Ubuntu releases:
sudo apt update
sudo apt install certbot python3-certbot-nginx -y
Then run Certbot against your domain. Replace example.com with your real domain, and add www.example.com if you serve the www version too:
sudo certbot --nginx -d example.com -d www.example.com
Certbot asks for an email address for expiry notices and asks whether to redirect all HTTP traffic to HTTPS. Say yes to the redirect. It then edits your server block, adds the certificate paths, and reloads Nginx. Load the site in a browser and check for the padlock. If it loads over HTTPS, you are done with the install.
Look at what Certbot added to your config. You should see lines like these in the server block:
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
Do not move these files by hand; Certbot manages them. If you need a certificate for a subdomain later, the same command with -d sub.example.com handles it, as the guide on setting up a free SSL certificate for a subdomain on Nginx explains.
Check the Certificate and the Redirect
A padlock in the browser is a good sign, but check the details. Run this from the server to see what the certificate actually covers and when it expires:
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates -subject
The subject should list your domain, and the dates should show roughly 90 days. Then test the redirect. A request to http://example.com should answer with a 301 to the HTTPS address:
curl -I http://example.com
If the response is a 200 over plain HTTP, the redirect did not apply. That usually means Certbot edited a different server block than the one actually serving the site, which happens when two blocks claim the same server_name. List the enabled sites and remove the duplicate.
WordPress sites have one extra trap: mixed content. The page loads over HTTPS, but images or scripts still point at http:// addresses, so the browser shows a warning instead of a padlock. The fix is to update the site URL in WordPress settings and search the database for old HTTP links. The full fix is covered in the guide on fixing mixed content warnings after moving WordPress to HTTPS.
SSL Certificate Renewal: How Certbot Handles It
Certbot installs a timer that tries to renew twice a day. On Ubuntu it runs through systemd, so check it with:
sudo systemctl status certbot.timer
sudo systemctl list-timers | grep certbot
Renewal only happens when a certificate is within 30 days of expiry, so most timer runs do nothing. That is normal. The important test is a dry run, which simulates a renewal without touching your live certificate:
sudo certbot renew --dry-run
Run this right after the install. If the dry run passes, renewal will almost certainly work when the time comes. If it fails, fix it now, while the site still has 90 days of cover, instead of discovering the problem from an expiry warning email.
Renewal fails for a few repeatable reasons. Port 80 closed after the install is the most common: someone tightens the firewall later and forgets that validation needs HTTP. A changed DNS record is next: the domain moved to another server, but Certbot still tries to renew on the old one. And a broken Nginx config blocks the reload step, so renewal cannot finish. The dry run catches all three if you run it after any firewall or DNS change.
Fix the Common Errors
| Error you see | What it usually means | Fix |
|---|---|---|
| Failed to connect to host for DVSNI challenge / connection refused | Port 80 is closed, or DNS points elsewhere | Open port 80, check the A record with dig |
| Could not find a matching server block | No server_name matches the domain | Fix server_name in the Nginx config, then rerun Certbot |
| Too many certificates already issued | Rate limit: 5 identical certificates per week | Wait, or reuse the existing certificate instead of reissuing |
| Certbot renew fails with a 404 | Another server block or app intercepts /.well-known/ | Make sure the challenge path reaches Nginx, not a proxy rule |
The rate limit deserves a warning of its own. Let’s Encrypt allows 5 certificates for the same set of domains per week. Repeatedly deleting and reissuing while you test will lock you out for days. Use the staging server for practice runs by adding --staging to the Certbot command, then run the real command once when the setup works.
When Certbot Is the Wrong Tool
Certbot fits a single server with a handful of domains. It fits less well when you run many servers behind a load balancer, or when you want wildcard certificates, which need DNS validation that the Nginx plugin cannot do. For that, use the DNS plugin for your provider, or a tool built around DNS challenges.
Caddy is worth a look if you are setting up a new server from scratch and want certificates handled with zero config. The trade-off is a smaller ecosystem of guides and modules than Nginx has. The comparison of Nginx vs Caddy for WordPress speed, SSL, and ease of setup lays out where each one wins.
For a normal Nginx site, though, Certbot is the shortest path to HTTPS. Install the plugin, run one command, confirm the redirect, and run a dry-run renewal. Do those four steps today, and set a calendar reminder to check the certificate expiry once a month until the first automatic renewal has actually happened.