Install a free SSL certificate with Certbot on Nginx or Apache
Updated 27 Nov 2026
HTTPS keeps your visitors' data private, removes the "Not secure" warning and helps your site in Google. Certbot gets a free certificate from Let's Encrypt and renews it every few months without you doing anything.
This guide is for Ubuntu with Nginx or Apache already serving your site.
Before you start
- An A record for your domain points to the server's IPv4 address, for both
@andwww. See Point your domain to your hosting or server. - The record has had time to spread. Check from your computer:
dig yourdomain.co.tz +shortshould show your server's IP. - Ports 80 and 443 are open in the firewall:
sudo ufw allow 80,443/tcp
1. Check your site is set up for the domain
Certbot finds the right site by its domain name.
- Nginx: your site's file in
/etc/nginx/sites-available/needs a line likeserver_name yourdomain.co.tz www.yourdomain.co.tz; - Apache: your site's file in
/etc/apache2/sites-available/needsServerName yourdomain.co.tzandServerAlias www.yourdomain.co.tz.
Test the settings:
sudo nginx -t
or for Apache:
sudo apache2ctl configtest
2. Install Certbot
For Nginx:
sudo apt update
sudo apt install -y certbot python3-certbot-nginx
For Apache:
sudo apt update
sudo apt install -y certbot python3-certbot-apache
3. Get the certificate
For Nginx:
sudo certbot --nginx -d yourdomain.co.tz -d www.yourdomain.co.tz
For Apache:
sudo certbot --apache -d yourdomain.co.tz -d www.yourdomain.co.tz
The first time, Certbot asks for an email address (for renewal warnings) and asks you to accept the terms. Use an address someone reads.
Certbot changes your site's settings to use the certificate and redirects HTTP to HTTPS. Open https://yourdomain.co.tz to check the padlock.
4. Check automatic renewal
Certificates last 90 days. Certbot sets up a timer that renews them before they expire. Check it exists:
systemctl list-timers | grep certbot
Then test a renewal without changing anything:
sudo certbot renew --dry-run
If it says Congratulations, all simulated renewals succeeded, you're done.
Add another domain or subdomain later
Run Certbot again with the new name. Make sure its DNS record points to the server first:
sudo certbot --nginx -d shop.yourdomain.co.tz
See which certificates you have:
sudo certbot certificates
Common problems
- "Timeout during connect" or "Connection refused": port 80 is blocked. Check
sudo ufw statusand that the web server is running. - "NXDOMAIN" or "DNS problem": the domain doesn't point to this server yet. Check the A record and wait.
- "Too many certificates already issued": Let's Encrypt limits how often you can request certificates for the same names. Test with
--dry-runfirst and wait before trying again. - Using Cloudflare or another proxy in front? Turn the proxy off while you get the certificate, or use that service's own certificate options.
Running a Node.js app? Host a Node.js app on your VPS with PM2, Nginx and free SSL covers the full setup.
Need a server? Order a Cloud VPS and get root access within minutes. For help, open a ticket and choose Technical.