How to Install a Free Let’s Encrypt SSL Certificate on Nginx (Certbot Guide)
A free Let’s Encrypt SSL certificate turns a plain HTTP site into an HTTPS site with no certificate fee and no yearly renewal order. Certbot, the tool from the EFF, handles the request, the proof that you control the domain, and the Nginx settings. This guide walks through the full install on Ubuntu with Nginx, then shows how to test renewal before the certificate ever gets close to expiry.
Before you start, point your domain at the server and wait for DNS to resolve to the server IP. Certbot proves control by reaching your server over HTTP, so a domain that still points elsewhere will fail validation. You can check with dig +short yourdomain.com or nslookup yourdomain.com from your own machine. The same LEMP base used here is covered in our guide to installing WordPress on a LEMP stack, which sets up Nginx, PHP, and MariaDB in the same order.
Free Let’s Encrypt SSL Certificate Basics Before You Install
Let’s Encrypt issues domain-validated certificates that last 90 days. The short life is deliberate: automation renews them, so a leaked key has a short window of use. Browsers trust Let’s Encrypt the same way they trust paid certificate authorities for ordinary sites, and there is no padlock difference between a free certificate and a paid one for domain validation. Paid certificates still make sense for extended validation or for warranties, but for a normal site the free certificate covers the encryption and identity check that visitors need.
Certbot offers two Nginx paths. The plugin path edits your Nginx config for you and adds the redirect from HTTP to HTTPS. The webroot path only writes a validation file and leaves your config alone, which suits servers with a custom setup. This guide uses the plugin path because it is the fastest correct route for a standard Nginx site, and it shows how to check what the plugin changed before you trust it.
Install Certbot and the Nginx Plugin
Ubuntu ships Certbot through snap and through apt. The snap build tracks new releases, and the Certbot project recommends it. Install it with:
sudo snap install --classic certbotsudo ln -s /snap/bin/certbot /usr/bin/certbot
If your server has no snap, install from apt instead with sudo apt install -y certbot python3-certbot-nginx. Either route gives you the certbot command and the Nginx plugin. Confirm the plugin is present with certbot plugins and look for nginx in the list. If it is missing, install the plugin package for your route before you continue, because the next command depends on it.
Request the Certificate with the Certbot Nginx Plugin
Make sure Nginx serves the domain over HTTP first, with a server block whose server_name matches the domain. Then run:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
Certbot asks for an email address for expiry notices, asks whether to redirect HTTP to HTTPS, and then writes the certificate files under /etc/letsencrypt/live/yourdomain.com/. Choose the redirect option for a normal site: it sends every HTTP request to HTTPS, which stops mixed content and duplicate HTTP pages. After the run, test the config with sudo nginx -t and reload with sudo systemctl reload nginx. Certbot reloads Nginx itself in most runs, but the test step catches a syntax problem before it becomes an outage.
Open the site in a browser and check the padlock, then run curl -I https://yourdomain.com and confirm a 200 response and a strict-transport-security header if your config sets one. If the browser warns about a name mismatch, the certificate was issued for a different name than the one you opened, which usually means the -d list missed a subdomain. Re-run Certbot with the full list of names instead of editing certificate files by hand.
Understand the Nginx SSL Configuration Certbot Writes
Certbot adds an SSL server block that points at fullchain.pem for the certificate chain and privkey.pem for the private key, and it includes /etc/letsencrypt/options-ssl-nginx.conf for protocol and cipher settings. Do not copy those files elsewhere or point other tools at them directly. The files under live/ are symlinks that Certbot updates on each renewal, so a copy goes stale while the symlink stays current. If you need the certificate in another service, point that service at the same live files or use a deploy hook to copy them after renewal.
Review the redirect block too. A clean setup has one HTTP block that returns a 301 redirect to HTTPS and one HTTPS block that serves the site. Two HTTPS blocks for the same name, or a leftover HTTP block that still serves content, both cause confusing behavior. For performance tuning after SSL works, see our guide to configuring Nginx FastCGI cache for WordPress, which builds on a working HTTPS setup.
Test Renewal Now, Not in 89 Days
Certbot installs a timer that tries renewal twice a day and only renews certificates within 30 days of expiry. That ssl certificate renewal path is the part to test, because it runs in the background and fails quietly. Test it now with a dry run:
sudo certbot renew --dry-run
A passing dry run proves the validation path still works, which is the part most likely to break later when a firewall rule or Nginx change blocks the challenge. Check the timer with systemctl list-timers | grep certbot. If no timer exists, the package install may have skipped it, and you should add a cron or timer entry rather than assume renewal happens. For wildcard names, the HTTP path does not work at all, and those names need the DNS validation route instead. Check the firewall rules with our guide to setting up a firewall with UFW on Ubuntu Server 24.04 if validation fails on port 80.
Fix the Failures You Are Most Likely to Meet
A timeout during validation usually means port 80 is closed or the domain points to the wrong server. Open port 80 in the firewall with sudo ufw allow 'Nginx Full' and re-check DNS. A 404 during validation usually means the server block for that name does not exist or Nginx serves a different root, so Certbot cannot place the challenge file where the validator looks. A rate limit error means too many failed or successful requests in a short window; Let’s Encrypt limits apply per domain, so wait and fix the cause before retrying, because repeated retries burn the allowance.
If renewal fails months later, the first place to look is the renewal config under /etc/letsencrypt/renewal/yourdomain.com.conf and the log at /var/log/letsencrypt/letsencrypt.log. The log names the exact challenge that failed. Common late failures are a changed firewall, a moved web root, and a plugin that stopped working after a system upgrade. Fix the cause, run the dry run again, and only then run a real renewal.
Keep the Private Key Private and the Renewal Automatic
The private key file should be readable only by root. Check with ls -l /etc/letsencrypt/live/yourdomain.com/ and never copy the key into a public folder, a code repository, or a support ticket. If a key leaks, revoke the certificate with sudo certbot revoke --cert-path /etc/letsencrypt/live/yourdomain.com/cert.pem and issue a new one. The free price of a certificate makes rotation cheap, so treat a leaked key as a reason to rotate at once, not as a problem to schedule later.
Set a calendar check for the first renewal even though automation should handle it. When the first real renewal succeeds, the system is proven end to end. After that, a monthly glance at the Certbot log is enough. SSL is one layer of server security, not the whole job, so keep the rest current with our guide to free SSL certificates for Docker apps if you run containerized services behind the same server.