Free certificates, issued and renewed automatically. A complete walkthrough from an HTTP-only Nginx site to HTTPS with redirects and a tested renewal timer.
Let’s Encrypt is a certificate authority that issues free TLS certificates, making HTTPS available to every site. Its client, Certbot, automates nearly everything — obtaining a certificate, rewriting the Nginx configuration and setting up renewal.
Before you start
You need an Ubuntu server (the steps were written for 20.04 and apply to later releases), a registered domain — example.com below — with an A record pointing at the server, and an application already served by Nginx.
Install Certbot
Install Certbot and its Nginx plugin with apt:
sudo apt install certbot python3-certbot-nginx
Confirm the Nginx configuration
Certbot finds the right server block by matching its server_name directive to the domains you request. Open your site’s configuration:
sudo nano /etc/nginx/sites-available/example.com
Find the existing server_name line. It should list your domain:
server {
listen 80;
server_name example.com www.example.com;
# …
}
/etc/nginx/sites-available/example.com
If you changed anything, validate the syntax and reload Nginx:
Field notes, deployment guides and research from the engineers who build web, cloud and mobile products at Aviox Blogs.
Insights & Understanding
Frequently Asked Questions
Answers to common questions regarding this article's topic, architecture, and practical applications.
Certbot finds the right server block by matching its server_name directive to the domains you request. Open your site’s configuration: sudo nano /etc/nginx/sites-available/example.com
Find the existing server_name line. It should list your domain: server {
listen 80;
server_name example.com www.example.com;
# …
}/etc/nginx/sites-available/example.com
If you changed anything, validate the syntax and reload Nginx:
General
Install Certbot and its Nginx plugin with apt:
General
If ufw is enabled, it probably only allows HTTP so far. Nginx registers profiles with ufw on installation, which makes the change simple:
General
Run Certbot with the Nginx plugin, passing each domain the certificate should cover with -d: sudo certbot --nginx -d example.com -d www.example.com
# or, for a single name
sudo certbot --nginx -d example.com
On first run you’ll be asked for an email address and to accept the terms of service. Certbot then proves you control the domain and asks whether to redirect all HTTP traffic to HTTPS. For a new site, choose the redirect. When it finishes, C
General
Let’s Encrypt is a certificate authority that issues free TLS certificates, making HTTPS available to every site. Its client, Certbot, automates nearly everything — obtaining a certificate, rewriting the Nginx configuration and setting up renewal.