Enable HTTPS AWS EC2

User
enable https in aws instance
Assistant
To enable HTTPS on your AWS EC2 instance, you'll need to follow these steps:

## Step 1: Connect to your EC2 instance via SSH

ssh -i /path/to/key.pem ubuntu@your-ec2-instance-ip

Replace `/path/to/key.pem` and `your-ec2-instance-ip` with your details.

## Step 2: Install Certbot (Let's Encrypt)

Update your packages first:

sudo apt update
sudo apt install certbot python3-certbot-apache -y

> **Note:** For Nginx, use:
>

> sudo apt install certbot python3-certbot-nginx -y
>

## Step 3: Generate SSL Certificate

– **Apache:**

sudo certbot --apache -d your-domain.com -d www.your-domain.com

– **Nginx:**

sudo certbot --nginx -d your-domain.com -d www.your-domain.com

Replace `your-domain.com` with your actual domain name.

Certbot will prompt you with some questions. Choose option to redirect HTTP to HTTPS.

## Step 4: Allow HTTPS Traffic (Security Group)

– Open your EC2 instance’s security group in the AWS console.
– Add an inbound rule:
– **Type:** HTTPS (port 443)
– **Source:** Anywhere (`0.0.0.0/0`)

## Step 5: Verify SSL Configuration

Visit:

https://your-domain.com

You should see your website served securely over HTTPS.

## Step 6: Automatic Certificate Renewal

Certificates issued by Let's Encrypt expire every 90 days. Setup automatic renewal:

sudo certbot renew --dry-run

Certbot automatically configures renewal via a cron job.

Your AWS EC2 instance now serves content securely using HTTPS.

User
we have http://ec2-51-20-60-238.eu-north-1.compute.amazonaws.com/
Assistant
AWS does **not issue SSL certificates** for the default EC2 domain (`ec2-*.compute.amazonaws.com`). To enable HTTPS on your EC2 instance, you must have your **own domain name**.

### Why HTTPS won't work on AWS-provided domains?

– Amazon's default EC2 domain (`ec2-*.compute.amazonaws.com`) isn't designed for public HTTPS certificates.
– SSL/TLS certificates require domain ownership verification, which is impossible with AWS-provided EC2 domains.

### Recommended Approach

You need your **own registered domain**. Here's what you should do:

## ✅ Step 1: Register a Domain Name

Use services such as:
– [AWS Route 53](https://aws.amazon.com/route53/)
– [GoDaddy](https://godaddy.com)
– [Namecheap](https://namecheap.com)

## ✅ Step 2: Point Domain to EC2 Instance

Add an **A record** to your DNS:

| Type | Name | Value |
|——|————-|———————–|
| A | @ (root) | `51.20.60.238` |
| A | www | `51.20.60.238` |

It might take a few minutes to propagate.

## ✅ Step 3: Install SSL (Let’s Encrypt)

Log into your EC2 instance and run:

### For Apache

sudo apt update
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d your-domain.com -d www.your-domain.com

### For Nginx

sudo apt update
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d your-domain.com -d www.your-domain.com

Follow prompts to complete installation.

## ✅ Step 4: Update Security Group

In your AWS EC2 Security Group, allow inbound rule:

– **HTTPS (443)** from source `0.0.0.0/0`.

## ✅ Step 5: Test

Visit your domain in browser:

https://your-domain.com

Your website should load securely with HTTPS.

**Summary:**
You **cannot use HTTPS** directly with the AWS-provided EC2 DNS. You **must use your own domain** to set up SSL and HTTPS.

Leave a Comment

Your email address will not be published. Required fields are marked *