Secure Nginx with a free Let's Encrypt SSL certificate

Install Certbot, issue a free certificate for your domain, redirect HTTP to HTTPS and make sure renewal runs on its own.

  • Beginner
  • Linux VPS
  • 2 min read

By RunRacks Team · Published

Let's Encrypt issues free, trusted TLS certificates. Certbot requests them, configures Nginx for HTTPS and renews them before they expire.

Before you start

  • Nginx serves your site over HTTP with a server_name that matches your domain. See Install Nginx.
  • Your domain's A record (and AAAA, if you use IPv6) points at the server. Check with dig +short example.com.
  • Ports 80 and 443 are open in your firewall. Let's Encrypt connects on port 80 to verify you control the domain.

1. Install Certbot

Ubuntu and Debian:

Terminal
sudo apt install -y certbot python3-certbot-nginx

AlmaLinux and Rocky Linux get it from EPEL:

Terminal
sudo dnf install -y epel-release
sudo dnf install -y certbot python3-certbot-nginx

2. Request the certificate

List every name the certificate should cover with -d:

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

Certbot asks for an email address for expiry warnings and for you to accept the terms. If it asks whether to redirect HTTP to HTTPS, choose redirect. It then edits your server block and reloads Nginx.

Open https://example.com. The browser should show a padlock.

3. Make sure renewal is automatic

Certificates last 90 days. Certbot installs a timer that renews them well before expiry. Check it:

Terminal
systemctl list-timers | grep -i certbot

On AlmaLinux and Rocky the timer may need enabling:

Terminal
sudo systemctl enable --now certbot-renew.timer

Then test a renewal without changing anything:

Terminal
sudo certbot renew --dry-run

Add more names later

Run the same command with the full list of names, old and new. Certbot offers to expand the existing certificate:

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

Troubleshooting

  • Challenge failed / timeout: port 80 is blocked or the domain does not point at this server yet. Check dig +short example.com and your firewall.
  • "Could not automatically find a matching server block": the server_name in Nginx does not include the exact names you passed with -d.
  • Renewal dry run fails: something changed since the first request, often port 80 being closed or a redirect rule blocking /.well-known/acme-challenge/.
  • See your certificates: sudo certbot certificates lists names and expiry dates.

Next steps

Was this guide helpful?

Still stuck?

Ask RunRacks AI for a quick answer, or open a ticket and our team will take a look at your server.

Linux VPS

Deploy a Node.js app with PM2 behind Nginx

Install a Node.js LTS release, keep your app running with PM2 across crashes and reboots, and serve it through Nginx with HTTPS.

  • Intermediate
  • Linux VPS
  • 3 min read

Linux VPS

Create an SFTP-only user limited to one folder

Give someone file access over SFTP without a shell, locked inside one folder. Configure internal-sftp with a Match block, set the chroot ownership right and test with WinSCP.

  • Advanced
  • Linux VPS
  • 5 min read