DEV Community

Darshan
Darshan

Posted on

Deploying First Website on AWS EC2 (step by step guide)

In this blog, I’ll walk through how I deployed my first website on an EC2 instance using AWS.
We will cover everything from launching an instance to connecting via SSH and hosting a static HTML page using Nginx.

Step 1: Create an AWS EC2 Instance

Go to AWS Console → EC2 Dashboard
Click on Launch Instance

Configuration:
Name: any-name
AMI: Amazon Linux 2023
Instance Type: t2.micro or t3.micro (Free Tier)

Key Pair:
Create a new key pair
Name : my-key-pair

Download .pem file (very important)

Step 2: Configure Security Group

Allow the following:

SSH (Port 22) → Anywhere (0.0.0.0/0)
HTTP (Port 80) → Anywhere (0.0.0.0/0)

Copy the public Ipv4 of your ec2 instance

Step 3: Connect to EC2 via SSH (Windows)

Open Command prompt and run:

ssh -i my-key-pair.pem ec2-user@PUBLIC_IP_OF_EC2

Step 4: Update the Server
sudo yum update -y

Step 5: Install Nginx
sudo dnf install nginx -y

Start and enable Nginx:

sudo systemctl start nginx
sudo systemctl enable nginx

Check status:

sudo systemctl status nginx

Step 6: Access Default Nginx Page

Open browser and go to:

http://PUBLIC_IP_OF_EC2

You shoud see:

Step 8: Replace Default HTML Page

Navigate to Nginx folder:

cd /usr/share/nginx/html

Edit file:

sudo nano index.html

Paste:

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Hello from EC2 Website</title>
</head>
<body>
  <h1>Hello from EC2</h1>
  <p>This is my first deployed website</p>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Save and exit.

Step 9: Restart Nginx
sudo systemctl restart nginx

Step 10: View Your Website

Open:

http://PUBLIC_IP_OF_EC2

U will see Your html page

Key Learnings
EC2 is a virtual server in the cloud
SSH allows remote access
Nginx serves web content
File paths matter (/ vs ~)
Security Groups control access

Top comments (0)