Free HTTPS certificate with Let's Encrypt and Certbot
Get a Let's Encrypt certificate for Nginx or Apache in minutes with Certbot, renew it automatically and fix typical errors.
Let's Encrypt issues free TLS certificates that every browser trusts. Certbot fetches them for you, adds them to Nginx or Apache and renews them automatically before they expire after 90 days.
Requirements
- Nginx or Apache is running and serves your website over HTTP
- The A record (and AAAA record if used) of your domain points to the server
- Port 80 is reachable from outside; Let's Encrypt uses it to verify that you own the domain
Install Certbot
For Nginx:
sudo apt update
sudo apt install certbot python3-certbot-nginx
For Apache:
sudo apt install certbot python3-certbot-apache
Get a certificate
sudo certbot --nginx -d example.com -d www.example.com
(use --apache instead of --nginx for Apache)
The first time, Certbot asks for an email address for expiry warnings and for the terms of service. Let's Encrypt then checks the domain, Certbot installs the certificate and, if you want, sets up the redirect from HTTP to HTTPS.
Open your site with https://; the padlock in the browser shows the new certificate.
Automatic renewal
Certbot creates a systemd timer that checks twice a day whether a certificate expires soon. Check it and test the renewal without changing anything:
systemctl list-timers | grep certbot
sudo certbot renew --dry-run
If the dry run completes without errors, there is nothing else you need to do.
List and remove certificates
sudo certbot certificates
sudo certbot delete --cert-name example.com
Wildcard certificates
A certificate for *.example.com is only available via the DNS challenge: Certbot asks for a TXT record _acme-challenge.example.com. You can do that by hand with --manual --preferred-challenges dns, but it cannot renew automatically that way. For long-term use you need a DNS plugin for your DNS provider. For most websites, individual names such as example.com and www.example.com are perfectly sufficient.
Common errors
| Message | Cause and fix |
|---|---|
Timeout during connect |
Port 80 is closed. Check UFW (sudo ufw status) and the panel firewall. |
DNS problem: NXDOMAIN |
The name does not exist in DNS yet or has not propagated. |
unauthorized / wrong IP |
The A or AAAA record points to another server. An outdated AAAA record is a common cause. |
too many certificates |
Too many attempts for the same name. Test with --staging until everything works. |
Always test new configurations with
--stagingfirst. The Let's Encrypt rate limits only apply to real certificates.
For the community
Know your stuff? Write a guide.
Share what you know: we review every submitted guide, publish it under your name and say thank you with credit for your services.