Certbot is the command-line tool that automates obtaining a free Let’s Encrypt SSL/TLS certificate and installing it on Nginx or Apache. In this guide we show a complete Certbot SSL setup on a Linux server: installing the package, issuing a certificate for example.com and www.example.com, testing automatic renewal with a dry run, and fixing the most common HTTP-01 validation errors. You can finish the basic setup in a few minutes on a server where you have root access.
Why Certbot and Let’s Encrypt Matter
A valid SSL/TLS certificate encrypts traffic between the visitor and your server and shows the padlock icon in the browser. Let’s Encrypt certificates are free, but they expire after 90 days. That short validity is why renewal automation is not optional; if the timer stops, your site shows a certificate warning. Certbot speaks the ACME protocol to Let’s Encrypt and proves domain ownership using either HTTP-01 or DNS-01 challenges. HTTP-01 is the default for most single-domain setups and publishes a temporary file on port 80. DNS-01 is needed for wildcard certificates and requires API access to your DNS provider.
Prerequisites
You need a Linux server with root or sudo privileges. Shared hosting generally does not give you the ability to install system packages and modify web server configuration, so we recommend a virtual server for this work. If you are still comparing hosting models, our VDS or dedicated server article explains where root-level control matters. When choosing a server for web hosting, also check the basics in our server buying guide.
Before running Certbot, verify these points:
- The domain’s A record points to the server’s public IP address.
- Ports 80 and 443 are open in your firewall.
- Nginx or Apache is installed and running.
- You have a backup of your web server configuration files.
Installing Certbot
Use your distribution package manager. On Ubuntu and Debian, Certbot and the Nginx plugin are in the default repositories:
# Ubuntu / Debian
sudo apt update
sudo apt install certbot python3-certbot-nginx # Nginx
# sudo apt install python3-certbot-apache # Apache
On RHEL, AlmaLinux, or Rocky Linux, use dnf:
# RHEL / AlmaLinux / Rocky Linux
sudo dnf install certbot python3-certbot-nginx # Nginx
# sudo dnf install python3-certbot-apache # Apache
On older CentOS 7 systems, enable EPEL first and use yum. After installation, confirm the version:
certbot --version
Issuing and Installing the Certificate
Run the appropriate command for your web server. Certbot will validate the domain, download the certificate, and update your web server configuration.
sudo certbot --nginx -d example.com -d www.example.com
# or for Apache
sudo certbot --apache -d example.com -d www.example.com
During the process, Certbot asks for an email address. That address is used for expiry and security notices. When the command succeeds, the certificate and key are stored under /etc/letsencrypt/live/example.com/. Open https://example.com in a browser to confirm the padlock.
If you only want to obtain the certificate and edit the web server configuration yourself, use the webroot method:
sudo certbot certonly --webroot -w /var/www/html -d example.com -d www.example.com
This command places the certificate in the same live directory without changing Nginx or Apache configuration. We use this when a site already has a custom server block and we do not want Certbot to insert redirect logic.
Automating Renewal
Let’s Encrypt certificates are valid for 90 days, so the renewal job must run regularly. On most modern distributions, Certbot creates a systemd timer during installation. Check it on Ubuntu or Debian with:
sudo systemctl status certbot.timer
sudo systemctl list-timers | grep certbot
On systems that use cron, inspect /etc/cron.d/certbot. The timer or cron job usually runs twice per day, but the certificate is only renewed when it is close to expiry.
Always test renewal without changing anything:
sudo certbot renew --dry-run
If the dry run completes without errors, run the real renewal command:
sudo certbot renew
Certbot reloads your web server after a successful renewal, so there is no need to restart Nginx or Apache manually.
Common Issues and How We Handle Them
- Port 80 is closed. HTTP-01 validation uses port 80. If the firewall blocks it, the certificate request fails. Open port 80 and 443 before running Certbot.
- DNS is not propagated. Use
dig example.comornslookup example.comto confirm the A record resolves to the server IP. - Rate limit reached. Let’s Encrypt applies a per-domain limit for failed attempts. Use
--dry-runfor testing and avoid repeated real requests. - Renewal fails later. Check
/var/log/letsencrypt/letsencrypt.log. The cause is usually a closed port, a changed virtual host, or a server that is unreachable at renewal time. - Nginx has no
server_name. Certbot cannot auto-configure a server block without a matchingserver_name. Use thecertonly --webrootmethod and add the SSL lines manually. - Wildcard certificate needed. HTTP-01 cannot issue a wildcard. You must use DNS-01 validation with a plugin for your DNS provider.
After the setup, run certbot renew --dry-run one more time and check systemctl status certbot.timer if available. That single test catches most future outages before the 90-day window ends.