How to Install Let's Encrypt SSL with Certbot (Nginx and Apache)
How to install Let's Encrypt SSL with Certbot on a Linux server: Nginx and Apache setup, automatic renewal, wildcard certificates and common errors.

Contents
If you're wondering how to install Let's Encrypt SSL on your own Linux server, the short answer is Certbot. Let's Encrypt is a non-profit certificate authority that issues free certificates trusted by every browser; Certbot is the tool that requests the certificate, adds it to your Nginx or Apache configuration and renews it before it expires. On a server that's set up correctly, the whole job takes a few minutes.
This guide covers what you need before you start, installing Certbot on Ubuntu, Debian and AlmaLinux, getting a certificate for Nginx and Apache, the webroot and standalone modes, where the certificate files live, automatic renewal, wildcard certificates, rate limits and the most common errors. For the background, see What is an SSL certificate?
Before you start
Let's Encrypt issues a certificate only after checking that you control the domain. With the default method, the HTTP-01 challenge, its servers connect to your domain on port 80 and look for a file that Certbot puts there. Three things have to be in place:
- DNS points to the server. The A record (and the AAAA record, if there is one) of every name you want in the certificate must point to your server's IP address. We cover the record types in What is DNS?
- Ports 80 and 443 are open. Port 80 is used for validation and renewal, port 443 for HTTPS itself.
- The web server already answers for the domain. There should be an Nginx server block or an Apache virtual host for the domain on port 80; our How to install Nginx guide shows how to create one.
Check the DNS records and open the ports:
dig +short example.com A
dig +short example.com AAAA
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
dig should print your server's IP address (if the command is missing, install it with sudo apt install dnsutils). Firewall rules are explained in How to use UFW; on AlmaLinux, run sudo firewall-cmd --permanent --add-service=http --add-service=https followed by sudo firewall-cmd --reload.
Installing Certbot
On Ubuntu and Debian, Certbot and its web server plugins are in the standard repositories. Install the plugin that matches your web server:
sudo apt update
sudo apt install certbot python3-certbot-nginx
For Apache, install python3-certbot-apache instead of python3-certbot-nginx.
The Certbot project itself recommends the snap package, which always carries the latest version and already includes both plugins. If you prefer it, remove the apt package first so the two don't clash:
sudo apt remove certbot
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
On AlmaLinux and Rocky Linux, Certbot comes from the EPEL repository:
sudo dnf install epel-release
sudo dnf install certbot python3-certbot-nginx
Getting a certificate for Nginx
sudo certbot --nginx -d example.com -d www.example.com
On the first run, Certbot asks for an email address and for you to accept the Let's Encrypt terms of service. Then it validates the domains, saves the certificate, finds the server block whose server_name matches, adds the listen 443 ssl and ssl_certificate lines to it (marked # managed by Certbot), sets up the redirect from HTTP to HTTPS and reloads Nginx.
Every name needs its own -d option; www.example.com isn't covered just because example.com is. To add a name later, run the command again with the full list of names.
Getting a certificate for Apache
sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d example.com -d www.example.com
Certbot looks for the virtual host whose ServerName or ServerAlias matches the domain, creates an HTTPS version of it (on Ubuntu and Debian a file ending in -le-ssl.conf under /etc/apache2/sites-available/), enables the SSL module and reloads Apache. On AlmaLinux, the plugin package has the same name, python3-certbot-apache.
Certificate only: webroot and standalone
If you don't want Certbot to touch your configuration, or there is no Nginx or Apache on the server, use certonly with one of these methods:
| Method | How validation works | When to use it |
|---|---|---|
--nginx / --apache | Certbot edits the web server configuration temporarily | The usual case; Certbot also installs the cert |
--webroot | A file is placed in the site folder; the web server keeps running | You manage the SSL configuration yourself |
--standalone | Certbot starts its own temporary web server on port 80 | No web server is running on port 80 |
| DNS challenge | A TXT record is added to the domain's DNS zone | Wildcard certificates, or port 80 is unreachable |
sudo certbot certonly --webroot -w /var/www/example.com -d example.com -d www.example.com
sudo certbot certonly --standalone -d mail.example.com
With webroot, Certbot writes the validation file to .well-known/acme-challenge/ inside the folder given with -w, so that folder has to be the one your web server serves for the domain. Standalone only works when nothing else is listening on port 80.
With certonly, you add the certificate paths to your configuration yourself, and the service has to be reloaded after every renewal. Add --deploy-hook "systemctl reload nginx" to the command; Certbot saves the hook and runs it after each successful renewal.
Where the certificates live
Certbot keeps everything under /etc/letsencrypt/. The files you use are in /etc/letsencrypt/live/example.com/:
| File | What it contains |
|---|---|
fullchain.pem | Your certificate plus the intermediate chain; the web server's file |
privkey.pem | The private key; never share it |
cert.pem | Your certificate only |
chain.pem | The intermediate certificates only |
In Nginx, the two lines look like this:
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
The files in live are links to the latest version in /etc/letsencrypt/archive/. Always point your configuration at the live path instead of copying the files somewhere else; copies aren't updated when the certificate is renewed. sudo certbot certificates lists your certificates, the names they cover and their expiry dates.
Automatic renewal
Let's Encrypt certificates are valid for 90 days, and Let's Encrypt has announced that lifetimes will get shorter over the coming years, so renewal has to be automatic. The Certbot package sets up a systemd timer that runs twice a day and renews any certificate that is close to expiry, by default when about 30 days are left:
systemctl list-timers | grep certbot
sudo certbot renew --dry-run
The timer is called certbot.timer with the apt package and snap.certbot.renew.timer with the snap. On AlmaLinux it is certbot-renew.timer, and you have to turn it on yourself with sudo systemctl enable --now certbot-renew.timer.
certbot renew --dry-run runs the whole renewal against Let's Encrypt's test environment without replacing your certificates. If it finishes without errors, renewal will work when the time comes. Renewal uses the same method as the first request, so port 80 has to stay open. Let's Encrypt no longer sends expiry warning emails, so add the certificate's expiry date to your monitoring; see our Server monitoring guide.
Wildcard certificates: the DNS-01 challenge
A wildcard certificate covers every subdomain, such as *.example.com. Let's Encrypt issues these only through the DNS-01 challenge: instead of a file on the web server, you prove control by adding a TXT record named _acme-challenge.example.com to the domain's DNS zone.
sudo certbot certonly --manual --preferred-challenges dns -d example.com -d '*.example.com'
Certbot shows the value for the TXT record and waits until you've added it at your DNS provider. A certificate obtained this way can't renew automatically, because the record has to be changed for every renewal. For a permanent setup, use the Certbot DNS plugin for your provider (for example the python3-certbot-dns-cloudflare package), which creates the record through the provider's API with a token you store on the server.
Rate limits
Let's Encrypt limits how many certificates can be issued for a domain and for the exact same set of names within a week, and how many failed validations are allowed within an hour. Normal use never gets near these limits; people hit them by running the same failing command over and over or by reinstalling a server several times in a row.
While you're still fixing your setup, add --dry-run to certonly or renew commands: the request goes to the test environment and doesn't count towards the real limits. If you do hit a limit, the error message says when you can try again; all you can do is wait.
Common errors
- DNS problem (NXDOMAIN): The domain has no A record yet, or the change hasn't spread to all DNS servers. Check with
dig +short example.comand wait a little after changing a record. - A stale AAAA record: If the domain has an AAAA record, Let's Encrypt prefers IPv6. A record left over from an old server can make validation fail even when the A record is right.
- Timeout during connect (likely firewall problem): Port 80 is closed. Check UFW, your provider's firewall and whether the web server is listening on port 80.
- Invalid response, 404 or unauthorized: The request reached a different site or folder. Check that
server_namematches the domain or, with webroot, that the-wpath is correct. - Could not automatically find a matching server block: The certificate was issued, but no server block has the domain in
server_name. Fix the line and run the command again. - Too many certificates or too many failed authorizations: You've hit a rate limit; wait for the time given in the message.
- CAA record prevents issuance: If the domain has CAA records, one of them must allow Let's Encrypt, for example
0 issue "letsencrypt.org". Check withdig +short example.com CAA.
The details of every run are in /var/log/letsencrypt/letsencrypt.log.
Testing the result
curl -I http://example.com
curl -I https://example.com
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -issuer -dates
The first command should return a 301 redirect to the https:// address, the second a normal response without a certificate error. The third prints who issued the certificate and its start and end dates. Also open the site in a browser and try both the www and the bare address.
Once HTTPS works everywhere, you can make browsers use it exclusively with HSTS; we explain it and the other headers in HTTP security headers.
Let's Encrypt on Nodesty servers
Nodesty AMD Ryzen 9 9950X VPS and AMD EPYC 7763 VPS plans come with NVMe disks and full root access, so you can install Certbot and run every command in this guide on your own server. Daily backups are free on VPS plans and are kept for 7 days. If you'd rather not manage a server, every Nodesty web hosting plan includes a free SSL certificate: once your domain points to the hosting, you enable it in cPanel or DirectAdmin, with no Certbot or command line involved.
Frequently Asked Questions
Is a Let's Encrypt certificate really free and safe?
Yes. Let's Encrypt is a non-profit certificate authority that issues domain validated certificates at no cost. They provide the same encryption as paid DV certificates and are trusted by every modern browser. The lifetime is shorter, but Certbot takes care of that with automatic renewal.
How long is a Let's Encrypt certificate valid?
Let's Encrypt certificates are valid for 90 days, and Let's Encrypt has announced that lifetimes will get shorter over the coming years. You don't have to track the date yourself, because Certbot checks twice a day and renews a certificate when about 30 days are left.
Do I have to renew the certificate by hand?
No. The Certbot package sets up a systemd timer that renews certificates automatically. You can see it with systemctl list-timers and test the whole process with sudo certbot renew --dry-run. If the test finishes without errors, renewal will work on its own.
Can I get a wildcard certificate from Let's Encrypt?
Yes, but only with the DNS-01 challenge. Instead of placing a file on your web server, you prove control of the domain by adding a TXT record named _acme-challenge to its DNS zone. For automatic renewal, use the Certbot DNS plugin for your DNS provider so that the record is created through the provider's API.
Why does Certbot say the challenge failed?
In most cases the domain doesn't point to the server yet, an old AAAA record points somewhere else or port 80 is closed in the firewall. Let's Encrypt has to reach your server over HTTP on port 80 to validate the domain. Fix DNS and the firewall, then test with the --dry-run option before trying again.
Do I need Certbot on Nodesty web hosting?
No. Every Nodesty web hosting plan includes a free SSL certificate that you enable from cPanel or DirectAdmin once your domain points to the hosting server. Certbot is for servers you manage yourself, such as a VPS with root access.
About the author
Nodesty Team · Infrastructure & Support
The Nodesty team runs our servers, network and DDoS protection day to day and answers customer support requests around the clock. These guides come from that work.
Related articles

WordPress Security: A Hardening Checklist for Your Site
WordPress security checklist: updates, strong logins and 2FA, file permissions, wp-config.php, no PHP in uploads, XML-RPC, firewalls and tested backups.

How to Set Up SSH Keys and Disable Password Login
How to set up SSH keys: create an ed25519 key with ssh-keygen, copy it to your Linux server, test the login and safely turn off password login.

How to Add a User on Linux and Give Sudo Rights
Add a user on Linux with adduser or useradd, give sudo rights, copy your SSH key, turn off root login, and lock, expire or delete users safely.