Back to blog

Free SSL on Your VPS: Let's Encrypt and Certbot with Nginx

IM Host EditorialOctober 25, 20267 min read
Free SSL on Your VPS: Let's Encrypt and Certbot with Nginx

Let's Encrypt issues free, browser-trusted SSL/TLS certificates. Certbot is the client that requests them, proves you control the domain, installs them into Nginx and renews them before they expire. On a VPS with Nginx the whole process takes a few minutes. Most problems come from DNS, port 80 or rate limits, so this guide covers those as well as the commands.

Let's Encrypt certificates are Domain Validated (DV). They prove control of the domain, which is all a browser needs to show the padlock. They do not verify who owns the business. That difference matters later, when we compare them with paid certificates.

Before you start

You need Nginx serving the site over plain HTTP with a correct server_name, DNS records pointing at this server, and ports 80 and 443 open:

dig +short A example.com
dig +short AAAA example.com
sudo ufw allow 'Nginx Full'
sudo nginx -t

Check the AAAA result carefully. Let's Encrypt prefers IPv6 when a domain has an AAAA record. If that record points to an old server, or Nginx does not listen on IPv6 (listen [::]:80;), validation fails even though the site works for you over IPv4. Either fix IPv6 or remove the AAAA record.

Port 80 must stay open even after you move to HTTPS. The standard HTTP-01 challenge always starts on port 80.

Step 1: Install Certbot

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

On Ubuntu 24.04 the apt packages are the simplest choice and receive security updates through Ubuntu. The Certbot project itself recommends the snap package, which follows new releases faster. Both work; do not install both, or you will have two renewal timers and two binaries.

Step 2: Request and install the certificate

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

Certbot asks for an email address and for agreement to the terms, then:

  1. Places a temporary token under /.well-known/acme-challenge/ through your Nginx config.

  2. Let's Encrypt fetches the token over HTTP for each name. That proves you control the domain.

  3. Certbot saves the certificate in /etc/letsencrypt/live/example.com/, adds the SSL lines to the matching server block and reloads Nginx.

--redirect adds a permanent redirect from HTTP to HTTPS. Include every name visitors use: a certificate for example.com does not cover www.example.com. The server block now contains lines like these:

# managed by Certbot
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

Do not edit the files in /etc/letsencrypt/live/. They are symbolic links that Certbot updates on every renewal.

Step 3: Confirm automatic renewal

Let's Encrypt certificates are short-lived: 90 days for years, and Let's Encrypt has announced it will shorten that further. Short lifetimes only work with automation. The Ubuntu package installs a systemd timer that runs certbot renew twice a day. Certbot only renews certificates that are close to expiry, by default within 30 days, so the frequent runs cost nothing.

systemctl list-timers | grep certbot
sudo certbot certificates
sudo certbot renew --dry-run

The dry run talks to the staging environment and goes through the full renewal without replacing anything. If it passes, real renewals will pass too, as long as DNS and port 80 do not change. Run it again after any change to your Nginx config or firewall.

With the --nginx installer, Certbot reloads Nginx after renewal on its own. If you obtained a certificate with certonly (as in the wildcard section below), Nginx keeps serving the old certificate from memory until it reloads. Add a deploy hook, which runs only after a successful renewal:

#!/bin/sh
# /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh
systemctl reload nginx
sudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh

One more change to know: Let's Encrypt stopped sending expiry reminder emails in 2025. If renewal breaks, nobody warns you. An external uptime monitor that checks certificate expiry is cheap insurance.

Rate limits: test on staging first

Let's Encrypt limits how many certificates you can request. At the time of writing the main limits are:

LimitValue
New certificates per registered domain50 per 7 days
Duplicate certificates (exact same set of names)5 per 7 days
Failed validations per hostname, per account5 per hour

Renewals of an existing certificate are treated more generously, so normal operation never hits these. The limits hurt when you are debugging: a script that reinstalls the server and requests a fresh certificate each time hits the duplicate limit by the sixth try, and you then wait days. Check the official rate limits page for the current numbers, and while you experiment, use the staging environment, which has much higher limits and issues untrusted test certificates:

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

Wildcard certificates with DNS-01

A wildcard certificate such as *.example.com covers every first-level subdomain: shop.example.com, api.example.com and so on. It does not cover example.com itself or deeper names like a.b.example.com, so request the bare domain alongside it.

Wildcards require the DNS-01 challenge: instead of serving a file over HTTP, you prove control by creating a TXT record at _acme-challenge.example.com. To renew automatically, Certbot needs API access to your DNS provider through a plugin. Plugins exist for many providers; this example uses Cloudflare:

sudo apt install -y python3-certbot-dns-cloudflare
sudo mkdir -p /root/.secrets
sudo nano /root/.secrets/cloudflare.ini
# dns_cloudflare_api_token = paste-a-token-limited-to-DNS-edit-for-this-zone
sudo chmod 600 /root/.secrets/cloudflare.ini

sudo certbot certonly --dns-cloudflare \
  --dns-cloudflare-credentials /root/.secrets/cloudflare.ini \
  -d example.com -d '*.example.com'

Give the API token permission to edit DNS for this one zone only. Anyone who reads that file can change your DNS, which is why the file is root-only. Then reference the certificate in Nginx yourself, because certonly does not edit any configuration:

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name example.com *.example.com;

    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;

    # ...
}

If your DNS provider has no plugin, --manual lets you create the TXT record by hand. Those certificates do not renew automatically, so treat that as a one-time test, not a setup. When debugging, check what public DNS returns:

dig +short TXT _acme-challenge.example.com

Reading the common errors

Unauthorized with a 404

Type:   unauthorized
Detail: Invalid response from http://example.com/.well-known/acme-challenge/...: 404

Let's Encrypt reached a web server, but not the one with the token. DNS points to another server, a CDN or proxy answers instead of your VPS, or a different server block catches the name. Check with sudo nginx -T | grep server_name.

Connection timeout

Type:   connection
Detail: Timeout during connect (likely firewall problem)

Port 80 is closed: UFW, the provider's firewall or Nginx not listening. Test from another machine with curl -I http://example.com.

NXDOMAIN

Detail: DNS problem: NXDOMAIN looking up A for www.example.com

The name has no DNS record yet, or the record has not propagated. Add it and wait before retrying, so you do not burn the failed-validation limit.

Too many certificates

too many certificates (5) already issued for this exact set of identifiers in the last 168h0m0s

You hit the duplicate limit. Wait for the window to pass, or add or remove a name so the set is different. Next time, use --staging until everything works.

When a free certificate is not enough

For most websites, APIs and admin panels, Let's Encrypt is the right choice. The encryption is the same strength as a paid certificate. A paid certificate makes sense when:

  • You need organization validation. OV and EV certificates confirm the legal entity behind the site. Some enterprise clients, banks, procurement processes and compliance audits require it.

  • You cannot run an ACME client. Some appliances, older systems and third-party platforms only accept a certificate file uploaded by hand.

  • Your organization requires a specific certificate authority, warranty or support contract.

Run it on IM HOST

Certbot needs root access, port 80 and control of your web server config. IM HOST Linux VPS plans give you full root on KVM, a dedicated IPv4 plus an IPv6 /64, and start from $5/month. If you need OV or EV validation, see our SSL certificates. If you would rather not manage certificates at all, Shared Hosting includes free SSL. Support engineers are available 24/7 if validation gets stuck.

More from our blog

Discover more practical guides and product insights from the IM Host team.

View all articles