Chapter 7: Static Website Hosting (3 OSes × 2 Web Servers)
7.13 Adding HTTPS (optional, needs a domain)
Browsers mark plain HTTP as "Not secure". Free TLS certificates are available from Let's Encrypt via certbot. You need a domain name whose A record points to your Elastic IP (see Chapter 9) and port 443 open.
# Ubuntu
sudo apt install -y certbot python3-certbot-nginx # or python3-certbot-apache
sudo certbot --nginx -d mysite.example.com # or --apache
# Amazon Linux 2023
sudo yum install -y certbot python3-certbot-nginx # or python3-certbot-apache
sudo certbot --nginx -d mysite.example.com
# CentOS Stream 9 (certbot comes from EPEL)
sudo yum install -y epel-release
sudo yum install -y certbot python3-certbot-nginx
sudo certbot --nginx -d mysite.example.com
Amazon Linux 2023: if the certbot package is not found
Install certbot in a Python virtual environment instead: sudo python3 -m venv /opt/certbot && sudo /opt/certbot/bin/pip install certbot certbot-nginx && sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot (use certbot-apache for Apache).
Certbot edits the server block, installs the certificate and sets up automatic renewal (check with sudo certbot renew --dry-run).