Sub topic 8
Obtaining Your First Let's Encrypt Certificate
This chapter assumes that you can use a Linux shell and sudo, nginx is installed, and you control a registered domain. Replace example.com and www.example.com with names that resolve to your server.
Prepare the server
Let's Encrypt must verify that you control each requested domain. For the HTTP-01 challenge, the certificate authority requests a temporary file from your server over HTTP. Confirm the following before running Certbot:
- DNS
AorAAAArecords point the domain names to this server. - TCP port 80 is reachable from the internet.
- nginx is running and accepts requests for the domain.
- A firewall or cloud security group allows inbound HTTP traffic.
- No proxy, load balancer, or separate server intercepts the challenge request.
Certbot is an ACME client. ACME is the protocol that lets a client request a certificate and complete domain validation automatically.
Install Certbot
On Debian or Ubuntu, install Certbot and its nginx plugin:
sudo apt update
sudo apt install certbot python3-certbot-nginx
certbot --versionThe nginx plugin lets Certbot temporarily arrange the HTTP-01 challenge. The certonly option requests and stores the certificate without changing your nginx configuration.
Test with the staging environment
Let's Encrypt provides a staging environment for testing. Staging certificates are not trusted by normal browsers, but they help you find DNS, firewall, and nginx problems without consuming production rate limits.
Run a test request first:
sudo certbot certonly --nginx --staging \
-d example.com -d www.example.comCertbot may ask for an email address, agreement to the terms of service, and permission to receive notices. Read each prompt before accepting it.
A successful result means that validation worked and Certbot stored a staging certificate. A failure usually identifies the domain that could not be validated. Correct the DNS or network problem before trying production.
Request the production certificate
After the staging request succeeds, request a trusted certificate from the production service:
sudo certbot certonly --nginx \
-d example.com -d www.example.comThe -d option adds a domain name to the certificate. One certificate can cover both the base domain and its www name. Every name must pass validation.
Certbot normally stores the active files under /etc/letsencrypt/live/example.com/. The certificate is not useful to visitors until nginx is configured to load these files. You will configure nginx in the next step of the process.
Exercise
Why should you run the staging command before the production command?
Show answer
Staging confirms that domain validation works without using production rate limits, and its certificate can be discarded safely.