Chapter 7: Static Website Hosting (3 OSes × 2 Web Servers)
7.13 Adding HTTPS (optional, needs a domain)
Quick answer: the short, self-contained version of this lesson is the guide How to Install a Free SSL Certificate on EC2 (Certbot).
Friends, HTTPS needs a domain first – you cannot get a Let's Encrypt certificate for a bare IP. If you don't have a domain yet, just read this section now and come back after Chapter 9.
मित्रांनो, HTTPS साठी आधी डोमेन लागतो – फक्त IP वर Let's Encrypt सर्टिफिकेट मिळत नाही. डोमेन नसेल तर हा सेक्शन आता वाचून ठेवा आणि Chapter 9 नंतर परत या.
दोस्तों, HTTPS के लिए पहले डोमेन चाहिए – सिर्फ़ IP पर Let's Encrypt सर्टिफ़िकेट नहीं मिलता. डोमेन न हो तो ये सेक्शन अभी पढ़कर रखो और Chapter 9 के बाद वापस आओ.
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).
Ravindra Bagale's Tip
Many students run certbot before the domain's A record points to the Elastic IP, or before opening port 443, and validation fails. First check with dig +short mysite.example.com that your IP shows up, open 443 in the security group, and then run certbot.
Ravindra Bagale's Tip – मराठी
खूप students domain चा A record Elastic IP कडे point होण्याआधी किंवा port 443 open करण्याआधी certbot चालवतात, आणि validation fail होतं. आधी dig +short mysite.example.com ने तुमचा IP दिसतो का ते बघा, security group मध्ये 443 open करा, मग certbot.
Ravindra Bagale's Tip – हिंदी
बहुत students domain का A record Elastic IP की तरफ point होने से पहले या port 443 open करने से पहले certbot चला देते हैं, और validation fail हो जाता है. पहले dig +short mysite.example.com से देखो कि तुम्हारा IP दिखता है या नहीं, security group में 443 open करो, फिर certbot.
Lab
Chala, domain asel tar certbot ne HTTPS lava aani sudo certbot renew --dry-run chalva. Domain nasel tar curl -I http://<PUBLIC_IP> aani browser madhe "Not secure" label bagha, aani HTTPS sathi lagnarya teen goshti (domain, A record, port 443) liha.