How to get a free SSL certificate with Let's Encrypt (Certbot)
GoGetSpace Engineering Last tested 10 min readTested onUbuntu 24.04AlmaLinux 9Fedora 45
Short answer
Point your domain's A record to your server and open ports 80 and 443. Install Nginx, Certbot and its Nginx plugin, and add a server block for your domain. Then run sudo certbot --nginx -d example.com -d www.example.com. Certbot gets a free Let's Encrypt certificate, adds it to Nginx and redirects HTTP to HTTPS. It renews automatically. On AlmaLinux, Rocky and Fedora, first start the renewal timer with sudo systemctl enable --now certbot-renew.timer.
Before you start
A domain that points to your server's IP. Check it with dig +short example.com. See Point your domain to your server. Delete any AAAA record for the domain: our servers are IPv4 only, and Let's Encrypt tries IPv6 first. If you use Cloudflare, set the records to for now.
No firewall turned on yet? Then the ports are already open, but set one up soon.
Tell Nginx about your domain
Certbot looks for an Nginx server block with your domain in server_name. If it can't find one, it puts the certificate in Nginx's default site, which is hard to undo. Create a folder for your site with a test page:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Open http://example.com (your domain) in a browser. You should see It works. If you see Nginx's default welcome or test page instead, check that server_name matches your domain exactly, then reload Nginx again. Fix this before you go on, because Let's Encrypt needs to reach the same site.
The first time, Certbot asks up to three questions:
Your email address. Let's Encrypt uses it for important notices about your account. On Fedora you can press Enter to skip. On Ubuntu 24.04 and AlmaLinux 9 you must type an address.
The Terms of Service. Type Y to agree. You can't get a certificate without it.
Sharing your email with the EFF, the non-profit behind Certbot. Type Y or N. It's up to you. Fedora's version doesn't ask this.
Then Certbot proves you control the domain, gets the certificate and adds it to Nginx:
Output
Requesting a certificate for example.com and www.example.com
Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/example.com/fullchain.pem
Key is saved at: /etc/letsencrypt/live/example.com/privkey.pem
This certificate expires on 2027-03-05.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.
Deploying certificate
Successfully deployed certificate for example.com to /etc/nginx/conf.d/example.com.conf
Successfully deployed certificate for www.example.com to /etc/nginx/conf.d/example.com.conf
Congratulations! You have successfully enabled HTTPS on https://example.com and https://www.example.com
Certbot edits your server block: it adds listen 443 ssl and the certificate paths (marked # managed by Certbot), and a second block that sends HTTP visitors to HTTPS. It doesn't ask about the redirect. It just adds it. Certbot reloads Nginx itself, so your site is on HTTPS right away. On AlmaLinux, Rocky and Fedora, the message about a scheduled task isn't true yet: you start the renewal timer yourself. See Automatic renewal.
Check that it works
Open https://example.com in a browser. It should load with no security warning. From the command line:
Bash
$ curl-I https://your-domain
Output
HTTP/1.1 200 OK
And http:// now redirects:
Bash
$ curl-I http://your-domain
Output
HTTP/1.1 301 Moved Permanently
To see your certificates and when they expire:
Bash
$ sudo certbot certificates
Output
Found the following certs:
Certificate Name: example.com
Serial Number: 6988f640f7eaf98c816e820f7d5911a4208
Key Type: ECDSA
Domains: example.com www.example.com
Expiry Date: 2027-03-05 20:35:47+00:00 (VALID: 89 days)
Certificate Path: /etc/letsencrypt/live/example.com/fullchain.pem
Private Key Path: /etc/letsencrypt/live/example.com/privkey.pem
Automatic renewal
Certificates from Let's Encrypt last 90 days. Certbot renews each one well before it expires (about 30 days before, on the versions we tested) and reloads Nginx. You don't need to do anything, but check that renewal works:
Bash
$ sudo certbot renew --dry-run
Output
Processing /etc/letsencrypt/renewal/example.com.conf
Simulating renewal of an existing certificate for example.com and www.example.com
Congratulations, all simulated renewals succeeded:
/etc/letsencrypt/live/example.com/fullchain.pem (success)
Certbot runs the renewal check twice a day with a systemd timer. Make sure the timer is running:
The timer starts by itself when you install Certbot. Check it:
Bash
$ systemctl list-timers |grep certbot
Output
Sun 2026-12-06 04:14:40 UTC 6h - - certbot.timer certbot.service
Start the timer yourself. It's installed but not started, so without this command your certificate won't renew:
Sun 2026-12-06 09:15:04 UTC 11h left - - certbot-renew.timer certbot-renew.service
Using Apache instead
Certbot works the same way with Apache. Skip the Nginx install and server block steps above, because Apache and Nginx can't both use port 80. Your Apache site needs a <VirtualHost *:80> with ServerName set to your domain, for example:
We haven't tested Apache here. AlmaLinux and Rocky need EPEL first, as above. Put the VirtualHost in /etc/httpd/conf.d/ instead. The SELinux fix and the renewal timer step apply here too.
We haven't tested Apache here. AlmaLinux and Rocky need EPEL first, as above. Put the VirtualHost in /etc/httpd/conf.d/ instead. The SELinux fix and the renewal timer step apply here too.
Certbot creates a separate HTTPS site file, ending in -le-ssl.conf. We tested Apache on Ubuntu 24.04 only.
If it doesn't work
What you see
What to do
Timeout during connect
Port 80 is blocked. Open ports 80 and 443 in your firewall (see above), then try again.
no valid A records found
Your domain doesn't point to a server yet. Add the A record, check it with dig +short, then try again. See Point your domain to your server.
unauthorized, or a 404 for the challenge file
The domain points somewhere else, or there's an old AAAA record. Check that dig +short shows this server's IP, and delete any AAAA record.
Certbot says it deployed the certificate to sites-enabled/default
Certbot found no server block for your domain and used the default site. Create your server block (see above) and run Certbot again.
Invalid email address
Your Certbot version needs an email address. Type one in.
403 Forbidden on AlmaLinux, Rocky or Fedora
SELinux label. Run sudo restorecon -Rv /var/www/example.com (with your domain).
too many certificates
You hit a Let's Encrypt limit (5 identical certificates a week). Wait a week before you try again. While you fix problems, test with sudo certbot certonly --nginx --dry-run -d example.com (with your domain). It doesn't count towards the limit.
The error shows a Cloudflare IP address, not your server's
Your record may be proxied. Set it to DNS only, get the certificate, then turn the proxy back on with SSL/TLS mode Full (strict).
Yes. Let's Encrypt is a non-profit certificate authority. Its certificates are free and trusted by all major browsers.
How long does a certificate last?
90 days today. Certbot renews it automatically, well before it expires. Let's Encrypt is moving to 64-day certificates in February 2027 and 45-day certificates in February 2028, and automatic renewal should handle that too.
Can I get a wildcard certificate (*.example.com)?
Yes, but not with the steps above. Wildcards need the DNS challenge, where Certbot adds a TXT record at your DNS provider. That needs a Certbot DNS plugin for your provider, such as Cloudflare's.
Can I get a certificate for my server's IP address?
Let's Encrypt now offers short-lived certificates for IP addresses, but they last only about 6 days and need extra setup. Use a domain name instead.
How do I remove a certificate?
Run sudo certbot delete --cert-name example.com (with your domain). Then delete every line marked # managed by Certbot from your server block, and the extra block Certbot added, and run sudo nginx -t before you reload. If you skip this, Nginx won't start, because the certificate files are gone.
Do I need to restart Nginx after renewal?
No. Certbot reloads Nginx itself after each renewal.
We haven't tested Apache here. AlmaLinux and Rocky need EPEL first, as above. Put the VirtualHost in /etc/httpd/conf.d/ instead. The SELinux fix and the renewal timer step apply here too.
We haven't tested Apache here. AlmaLinux and Rocky need EPEL first, as above. Put the VirtualHost in /etc/httpd/conf.d/ instead. The SELinux fix and the renewal timer step apply here too.