Sub topic 5
Preparing DNS Records, Ports 80 and 443, and the Firewall
This chapter assumes you can use a Linux shell and sudo, understand basic DNS records, and have nginx installed on a server. You also need a registered domain and permission to change its DNS records and firewall rules.
Before Certbot can request a certificate, a certificate authority (CA) must verify that your server controls the requested domain. The most common method is the HTTP-01 challenge. The CA connects to port 80, requests a temporary file from your domain, and checks the response. Your DNS records must therefore point the domain to the correct server, and the server must accept connections on port 80.
Point the domain at the server
Find the server's public IPv4 address:
curl -4 https://icanhazip.comAt your DNS provider, create an A record for the domain:
| Name | Type | Value | Purpose |
|---|---|---|---|
| `@` | `A` | `203.0.113.10` | Points `example.com` to the server |
| `www` | `A` | `203.0.113.10` | Points `www.example.com` to the server |
Replace 203.0.113.10 with the actual address. The name @ usually represents the domain itself.
If the server has a public IPv6 address, add matching AAAA records. Do this only when IPv6 reaches the same nginx server and is correctly configured. A stale or incorrect AAAA record can cause validation to use IPv6 and fail even when IPv4 works.
DNS changes are cached according to the record's time to live (TTL). Check the records from your server or another network:
dig +short A example.com
dig +short A www.example.com
dig +short AAAA example.comThe returned addresses must match the intended server. If a record has multiple addresses, every address must serve the domain correctly.
Open ports 80 and 443
Port 80 carries HTTP traffic and is required by HTTP-01 validation. Port 443 carries HTTPS traffic after TLS is configured. Permit both ports in every firewall layer:
- The cloud provider's security group or network ACL.
- The server's host firewall.
- Any external router or load balancer.
- nginx's listening configuration.
On a server using UFW, inspect the current rules and allow web traffic:
sudo ufw status verbose
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reloadConfirm that nginx is listening:
sudo ss -ltnp | grep -E ':(80|443)\b'Before TLS is configured, port 80 should normally be listening. Port 443 may not appear until nginx has a TLS server block.
Confirm HTTP reachability
Create or check the nginx site configuration so its server_name contains every name you will request:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/html;
}Test and reload nginx:
sudo nginx -t
sudo systemctl reload nginx
curl -I http://example.comA response such as 200 OK or 404 Not Found proves that the server answered. A timeout usually indicates a firewall, routing, or provider rule. A response from the wrong website usually indicates an incorrect server_name or a different server address.
Exercise
DNS resolves example.com to the correct IPv4 address, but Certbot reports a connection timeout. What should you check first?
Show answer
Check port 80 in the cloud firewall and host firewall, confirm nginx is listening on port 80, and test curl -I http://example.com from an external network.