Web servers and networking · Beginner · 10 min
How to Get Free HTTPS for Your Site with Let's Encrypt and Nginx
By Padding · Updated 15 Nov 2026
Ubuntu 26.04.1 LTS · Nginx 1.30 · Certbot 5.10
You will install Certbot 5.10, get a free Let's Encrypt certificate for your domain, have Nginx serve it over HTTPS, and confirm that it renews on its own.
On this page
HTTPS encrypts traffic between your visitors and your server, and browsers warn about sites without it. Let's Encrypt is a free certificate authority. Certbot is the tool that proves to Let's Encrypt that you control a domain, collects the certificate, and installs it in Nginx.
In this tutorial you will install Certbot, request a certificate for one domain, let Certbot add the HTTPS settings to Nginx, and test that renewal works. It is the fifth tutorial in the series Your first production server.
This tutorial follows the official Certbot instructions for Nginx on Ubuntu with snap, and its documentation, for Certbot 5.10. Replace example.com with your own domain throughout.
Step 1 · Check the site works on HTTP first
Let's Encrypt connects to your server on port 80 to check you control the domain. If the plain site does not load, the certificate request will fail.
Make sure there is a server block that names your domain. If you followed /tutorials/host-multiple-sites-with-nginx-server-blocks you have one already. The important line is:
server_name example.com www.example.com;Test and reload Nginx:
sudo nginx -t && sudo systemctl reload nginxCheck it worked
From your own computer, run curl -I http://example.com/. You should get a 200 or a redirect, not a timeout or a connection error. Confirm DNS with dig +short example.com, which must print your server's IP address. If DNS has not updated yet, wait before going on.
Step 2 · Install Certbot
The Certbot project recommends the snap package. Remove any Certbot installed through apt first, because two copies conflict.
sudo apt remove certbot python3-certbot-nginxIf apt says the packages are not installed, that is fine. Snap is included with Ubuntu server. Install Certbot and put it on your path:
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/local/bin/certbotCheck it worked
certbot --versionIt prints certbot 5.10.0 or a later release.
Step 3 · Open the firewall for HTTPS
If UFW is on, allow port 443 as well as 80. The nginx.org package has no UFW profile, so use port numbers.
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw statusCheck your cloud provider's firewall too, if it has one.
Step 4 · Get the certificate
Run Certbot with the Nginx plugin. It obtains the certificate and edits your Nginx configuration.
sudo certbot --nginx -d example.com -d www.example.comCertbot asks for an email address, for expiry warnings and important notices, and asks you to accept the Let's Encrypt terms of service. It may ask whether you want to share your email with the EFF; that is optional. It then contacts Let's Encrypt, proves control of each name over port 80, and saves the certificate under /etc/letsencrypt/live/example.com/. In the server block that matches your domain, it adds listen 443 ssl, the certificate paths and a redirect from HTTP to HTTPS.
If you only want the certificate, and would rather write the Nginx settings yourself, use sudo certbot certonly --nginx -d example.com instead.
While testing, you can add --staging to use Let's Encrypt's test servers. They have much higher rate limits, so a mistake does not lock you out. Staging certificates are not accepted by browsers. Remove the flag for the real request. The limits for the real service are listed at letsencrypt.org/docs/rate-limits.
Check it worked
Certbot ends with Congratulations! You have successfully enabled HTTPS on https://example.com. Open https://example.com in a browser and look for the padlock. Or from your computer:
curl -I https://example.com/The first line is HTTP/2 200 (or HTTP/1.1 200 OK). Then check that plain HTTP redirects:
curl -I http://example.com/It returns 301 with a location: https://example.com/ header.
Troubleshooting
Most failures happen during the challenge, and Certbot prints the reason.
Timeout during connect (likely firewall problem): port 80 is blocked. Check UFW and your provider's firewall.DNS problem: NXDOMAIN looking up A for example.com: the record does not exist or has not spread yet. Check withdig +short example.com.unauthorized ... Invalid response: the domain points at a different server, or another server block catches the request. Look at/var/log/nginx/error.log.Could not automatically find a matching server block: noserver_nameequals your domain. Add it, reload Nginx and run Certbot again.too many certificates already issued: you hit a rate limit. Wait, and use--stagingfor experiments.
The log of every run is in /var/log/letsencrypt/letsencrypt.log.
Step 5 · Check that renewal works
Certificates are short-lived, so they must renew without you. Certbot installs a scheduled task for this. Find it:
systemctl list-timers | grep certbotThe snap defines a renew task with a timer, which systemd lists as snap.certbot.renew.timer, so expect a line with that name. If the command prints nothing, look for a certbot renew entry in /etc/crontab or /etc/cron.*/* instead. Then test a full renewal against the staging servers, without changing your real certificate:
sudo certbot renew --dry-runThe output ends with Congratulations, all simulated renewals succeeded. If it fails, fix that now. A failure here would also happen on the real renewal.
List the certificates Certbot manages, with their domains and expiry dates:
sudo certbot certificatesSince Certbot 4.0.0, a certificate is renewed when about a third of its lifetime is left. After a renewal that used the Nginx plugin, Certbot reloads Nginx for you. Its log line reads Reloading nginx server after certificate renewal. To see which certificate a visitor gets, run curl -vI https://example.com/ 2>&1 | grep "expire date".
Next steps
- Serve several domains, each with its own certificate:
/tutorials/host-multiple-sites-with-nginx-server-blocks. - Send HTTPS traffic to an app:
/tutorials/nginx-reverse-proxy-for-a-node-app. - Tell browsers to use only HTTPS and add other protections:
/tutorials/add-security-headers-in-nginx. - Sources: certbot.eff.org/instructions, eff-certbot.readthedocs.io/en/stable/using.html.
Related tutorials
- How to Put Nginx in Front of a Node.js App as a Reverse ProxyYou will install Node.js 26, run a small app on a local port, and configure Nginx 1.30 to pass public traffic to it with the headers your app needs.
- How to Load Balance Traffic Across Servers with NginxYou will spread requests across three backends with an Nginx upstream block, weight them, keep a spare in reserve, and watch Nginx route around a backend that stops answering.
- How to Install Nginx on Ubuntu 26.04You will install the current stable Nginx 1.30 from the official nginx.org repository on Ubuntu 26.04, serve its test page, and learn where its files live and how to reload it safely.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials