Ravindra BagaleCourses & study guides मराठी Track your progress

Chapter 7: Static Website Hosting (3 OSes × 2 Web Servers)

7.13 Adding HTTPS (optional, needs a domain)

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.

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.

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.