Nginx + Let's Encrypt: Free SSL With Certbot and an HTTP to HTTPS Redirect

Key Takeaways
- ✓Certbot's Nginx plugin gets the certificate and edits your config in one command.
- ✓Port 80 must be reachable and DNS must point to the server first.
- ✓Certificates last 90 days; Certbot's timer renews them automatically.
- ✓A 301 redirect sends all HTTP traffic to HTTPS.
Table of Contents
- •Nginx + Let's Encrypt: Free SSL With Certbot and an HTTP to HTTPS Redirect
- •Before You Start
- •Step 1: Install Certbot
- •Step 2: Get the Certificate
- •Step 3: Redirect HTTP to HTTPS
- •Step 4: Confirm Auto-Renewal
- •Optional: Redirect www to non-www (or the reverse)
- •Wildcard Certificates
- •Common Certbot Errors
- •Frequently Asked Questions
- •Rather Not Manage Certificates Yourself?
Nginx + Let's Encrypt: Free SSL With Certbot and an HTTP to HTTPS Redirect
Let's Encrypt gives you trusted SSL certificates for free, and Certbot automates the whole process for Nginx: it proves you own the domain, installs the certificate, updates your server block and renews it before it expires. This guide assumes Ubuntu or Debian with Nginx already serving your site on port 80.
Before You Start
- Your domain's A record points to this server (check with
dig +short example.com). - Port 80 and 443 are open in the server firewall and any cloud firewall. Let's Encrypt connects on port 80 to verify the domain. On Oracle Cloud, see opening ports 80 and 443.
- An Nginx server block already uses
server_name example.com www.example.com;.
Step 1: Install Certbot
sudo apt update
sudo apt install certbot python3-certbot-nginxCertbot's own recommended method is the snap package (sudo snap install --classic certbot), which stays more up to date; either works.
Step 2: Get the Certificate
sudo certbot --nginx -d example.com -d www.example.comCertbot asks for an email (for expiry warnings), verifies the domain, installs the certificate and adds the ssl_certificate lines to your server block. Certificates are stored in /etc/letsencrypt/live/example.com/.
Step 3: Redirect HTTP to HTTPS
Certbot can add the redirect for you. If it did not, add a separate server block for port 80:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}Keep the /.well-known/acme-challenge/ path reachable if you use a more complex setup; Certbot's Nginx plugin handles this automatically during renewal.
Then test and reload:
sudo nginx -t && sudo systemctl reload nginxStep 4: Confirm Auto-Renewal
Let's Encrypt certificates are valid for 90 days. Certbot installs a systemd timer (or snap timer) that renews them automatically. Check it with a dry run:
sudo certbot renew --dry-run
systemctl list-timers | grep certbotOptional: Redirect www to non-www (or the reverse)
server {
listen 443 ssl;
server_name www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
return 301 https://example.com$request_uri;
}Pick one canonical version and redirect the other so search engines see a single site.
Wildcard Certificates
A wildcard certificate (*.example.com) cannot use the normal HTTP check; it needs a DNS challenge. Use a Certbot DNS plugin for your DNS provider, or --manual --preferred-challenges dns (manual certificates do not renew automatically).
Common Certbot Errors
- Timeout during connect (likely firewall problem): port 80 is blocked by the server or cloud firewall.
- DNS problem: NXDOMAIN or the wrong IP: the domain does not point to this server yet; wait for DNS to update.
- Could not automatically find a matching server block: add the domain to a
server_nameline, reload Nginx, and run Certbot again. - Too many certificates already issued: you hit Let's Encrypt's rate limits from repeated attempts; use
--dry-runor the staging server while testing.
Other Nginx problems are covered in common Nginx errors and fixes, including 403 Forbidden.
Frequently Asked Questions
Is Let's Encrypt really free?
Yes. Certificates are free and trusted by all major browsers. They last 90 days and renew automatically with Certbot.
How do I redirect HTTP to HTTPS in Nginx?
Add a server block on port 80 with return 301 https://$host$request_uri;, then run nginx -t and reload.
How do I renew a Let's Encrypt certificate manually?
Run sudo certbot renew. Normally you never need to, because the Certbot timer does it twice a day when renewal is due.
Do I need to restart Nginx after renewal?
Certbot's Nginx plugin reloads Nginx after a successful renewal, so the new certificate is used automatically.
Rather Not Manage Certificates Yourself?
RackUp IT managed hosting issues and renews SSL certificates automatically and keeps the web server configured and patched, so HTTPS never quietly expires on you.
Unsure Which Cloud Hosting Plan Fits Your Site?
Answer 4 quick diagnostic questions to estimate the server CPU, RAM and storage you need with transparent pricing.
Cloud Infrastructure Engineer.
Related Posts
VPS HostingVultr Alternatives in 2026: VPS Hosting for Developers Compared
Vultr's Regular Performance prices compared with DigitalOcean, Linode, Hetzner and a fixed-plan VPS at the 8 GB size, plus when container hosting fits better.
VPS HostingWhat Is a VPS? Virtual Private Servers Explained
A VPS (virtual private server) is a virtual machine with its own operating system, resources and root access. How it works, uses, and when you need one.
VPS HostingLinode (Akamai) Alternatives in 2026: VPS Hosting Compared
Linode's shared CPU prices from Akamai's own API, compared with DigitalOcean, Vultr and a fixed-plan VPS, plus when container hosting makes more sense.