Let’s Encrypt on Nginx: Free HTTPS From Install to Auto-Renewal

HTTPS used to cost money and take a full afternoon to set up. That changed when Let’s Encrypt started issuing free certificates, and Certbot made the install a few commands instead of a manual signing request. If you run Nginx on your own server, this guide shows how lets encrypt nginx free https works end to end: install Certbot, issue a certificate, point Nginx at it, and set up renewal so you never have to think about expiry dates again. You need a Linux server, a domain name that already points at it, and shell access. No paid certificate and no control panel are required.

What You Get With a Free Certificate

A Let’s Encrypt certificate gives browsers the same padlock and the same encrypted connection as a paid certificate. The encryption is the same, and modern browsers trust it the same way. The differences sit in the details. Let’s Encrypt certificates last 90 days instead of a year, so renewal has to be automatic. They also prove only that you control the domain, which is called domain validation. That is enough for a blog, a shop, a SaaS app, or an API. It does not prove your company identity, and for most small sites that level of proof is never needed.

There is one more limit worth knowing before you start. Let’s Encrypt caps how many certificates you can request for one domain in a week. The rate limit is 50 certificates per registered domain per week, which sounds generous until a bad script requests a new certificate on every deploy. Request once, store the files, and renew the same certificate instead of issuing a fresh one. If you hit the limit, you wait; there is no paid way around it. The result is a free SSL certificate Nginx can serve over port 443, with no renewal bill attached.

Check These Three Things Before You Install Certbot

Most failed installs come from a skipped check, not from Certbot itself.

First, your domain must resolve to the server. Run dig +short example.com and confirm the IP matches your server. Certbot proves control by reaching your server over HTTP, so a DNS record that still points at an old host will fail validation every time. Second, port 80 must be open and reachable. Certbot uses an HTTP challenge on port 80 by default, even though the end goal is HTTPS. If a firewall blocks port 80, validation fails with a connection error. Third, Nginx must already serve the domain over HTTP. Certbot reads your server blocks to find the domain and to write the HTTPS version. If you are still planning the Nginx side, read our guide on what a reverse proxy is and how Nginx handles one before you wire up certificates, since the same server block carries both jobs.

Install Certbot and Issue Your First Certificate

On Ubuntu and Debian, install the Certbot Nginx plugin from the system packages. Avoid installing Certbot with pip on a production server, since the packaged version gets security updates with the rest of the system.

sudo apt update
sudo apt install certbot python3-certbot-nginx

With the plugin installed, one command requests the certificate and rewrites your Nginx config to use it:

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

Certbot asks for an email address for expiry notices, then asks whether to redirect all HTTP traffic to HTTPS. Say yes to the redirect unless you have a clear reason to keep plain HTTP reachable. The command then writes the certificate files under /etc/letsencrypt/live/example.com/ and reloads Nginx. Test the result in a browser and with curl -I https://example.com, which should return a 200 or a 301, not a certificate warning. This nginx https setup takes about ten minutes when DNS and the firewall are already correct, and most of that time is typing.

What Certbot Changes in Your Nginx Config

Certbot edits your server block in place. It adds listen 443 ssl;, the paths to fullchain.pem and privkey.pem, and an include line for the SSL options file it manages. It also adds a second server block that redirects port 80 to HTTPS.

Two habits keep this safe. First, back up the Nginx config before you run Certbot, with a plain copy of the file. If the edit ever goes wrong, restoring one file beats rebuilding the block from memory. Second, never edit the certificate files by hand. They are symlinks that Certbot updates on renewal, and a manual edit breaks the renewal chain. If you need to change which domains a certificate covers, run Certbot again with the new domain list and let it update the files. If the site sits behind Cloudflare or another proxy, read our zero-downtime Nginx reverse proxy guide with Cloudflare and HTTP/3 first, since the proxy changes which server sees the validation request and where the redirect should live.

Lets Encrypt Nginx Free HTTPS Auto-Renewal That Runs Itself

Certbot installs a renewal timer when the package installs. On systems with systemd, a timer runs certbot renew twice a day and only renews certificates that are within 30 days of expiry. Certificates last 90 days, so this gives you a wide margin. Check that the timer exists and is active:

sudo systemctl status certbot.timer
sudo certbot renew --dry-run

The dry run tests the full renewal path against the staging server without touching your live certificate. If it passes, renewal will work when the real date comes. If it fails, fix it now, while the certificate is still valid, instead of discovering the failure from an expiry warning. Certbot nginx auto renewal depends on two things staying true: port 80 must stay open, and Nginx must stay running so Certbot can reload it after renewal. A server where someone closed port 80 “because everything is HTTPS now” is the most common renewal failure in the wild, and it is easy to miss because the site keeps working until the certificate expires.

When a renewal succeeds, Certbot reloads Nginx on its own. You do not need a cron job of your own, and adding one that also runs certbot renew can cause two processes to fight over the same lock file. One timer is enough. If your setup is unusual, for example a staging copy of the site on a second machine, our guide to setting up a staging environment on a separate VPS shows how to keep test servers from requesting certificates for the live domain.

When Renewal Fails: The Usual Causes

Renewal failures almost always fall into three groups. The first is network access: port 80 closed, a firewall rule changed, or DNS moved to a new server while the certificate still points at the old one. The second is a stopped or broken Nginx: Certbot needs the web server running so it can reload the new certificate into place, and a config error that stops Nginx from starting will block renewal too. The third is a changed domain setup, for example a server name edited in the block without reissuing the certificate, so the names on the certificate no longer match the names Nginx serves.

Read the Certbot log at /var/log/letsencrypt/letsencrypt.log before you change anything. It names the exact challenge that failed and the error the validation server returned, which usually points straight at one of the three groups above. Fix that cause, then run sudo certbot renew --dry-run again to confirm the path is clear. If the dry run passes, the next scheduled renewal will succeed on its own.

Wildcard Certificates and Other Edge Cases

A wildcard certificate covers *.example.com along with the base domain, so one certificate serves every subdomain. Wildcards need DNS validation instead of HTTP validation, which means Certbot has to write a TXT record through your DNS provider’s API. That only works if your provider has a Certbot plugin and you store an API token on the server. If you have three subdomains, three normal certificates are simpler and safer than one wildcard with an API token sitting on disk. If you have thirty, the wildcard earns its keep.

There are two more cases worth a mention. If Nginx serves several unrelated domains from one server, give each domain its own certificate rather than one shared certificate with every name on it, so a renewal problem on one domain never touches the others. And if you are choosing between Nginx and Apache for a busy site before you set up HTTPS at all, our Nginx versus Apache comparison for high-traffic servers covers the trade-offs that matter at scale. Once the certificate is live, check the expiry date in your calendar for the first cycle, then trust the timer. A free certificate that renews itself is the whole point of lets encrypt nginx free https, and after the first successful renewal you can stop watching it.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.