Deploy and Terminate Nginx on Amazon Linux EC2

๐ Introduction
In this guide, Iโll show you how to set up a basic web server using Nginx on an Amazon EC2 instance. Youโll install Nginx, create your own HTML page, and access it from any browser using your EC2โs public IP address.
This tutorial is for beginners who want to learn how static websites are hosted in the cloud using Linux and Nginx โ no Docker involved.
โ๏ธ Step 1: Launch EC2 Instance on AWS
Go to AWS Console โ EC2 โ Launch Instance
Choose Amazon Linux 2023 (Free Tier eligible)
Select t2.micro instance type
Select or create a key pair (
.pem
file)In Security Group, add:
Type:
HTTP
, Port:80
, Source:Anywhere (0.0.0.0/0)
Type:
SSH
, Port:22
, Source: Your IP
Launch your instance ๐
๐ Step 2: Connect to EC2 via SSH
From your terminal, connect like this:
ssh -i your-key.pem ec2-user@<your-ec2-public-ip>
Replace
your-key.pem
with your actual key file nameReplace
<your-ec2-public-ip>
with the IP shown in the EC2 dashboard
Once connected, youโll see:
[ec2-user@ip-... ~]$
โ You're now logged into your EC2 Linux machine.
๐ Step 3: Install and Start Nginx
- Install Nginx:
sudo dnf install nginx -y
- Start Nginx:
sudo systemctl start nginx
- Check if itโs running:
sudo systemctl status nginx
You should see: active (running)
โ
๐ Step 4: Access Default Nginx Page in Browser
In your browser, enter:
http://<your-ec2-public-ip>
๐ Youโll see the default Nginx Welcome Page โ it means the web server is working correctly!
๐ Step 5: Add Your Own HTML Page (Static Website)
Letโs replace the default page with your own:
- Go to Nginx web root:
cd /usr/share/nginx/html
- Create your own index.html:
sudo nano index.html
- Paste this sample content:
<!DOCTYPE html>
<html>
<head>
<title>My Static Site</title>
</head>
<body>
<h1>Welcome to My Website!</h1>
<p>This page is hosted on AWS EC2 using Nginx.</p>
</body>
</html>
- Save and Exit:
Press
Ctrl + O
, thenEnter
to savePress
Ctrl + X
to exit nano
- Refresh the Browser Page:
http://<your-ec2-public-ip>
๐ฅ Youโll now see your custom HTML page live on the internet!
๐ Step 6: Check Services and Ports (Optional)
- See all running services:
systemctl list-units --type=service --state=running
- Check which service is using which port:
sudo ss -tulpn
Nginx will be shown using port 80
.
๐ Step 7: Stop or Disable Nginx (Optional)
To stop the server:
sudo systemctl stop nginx
To prevent it from auto-starting on reboot:
sudo systemctl disable nginx
Check status again:
sudo systemctl status nginx
๐ก Tips and Learnings
EC2 is your virtual machine in the cloud ๐ฅ๏ธ
Nginx is a fast, lightweight web server ๐
You host a site by replacing the
index.html
fileAlways ensure port 80 is open in the security group
Use
systemctl
to manage services andss
to inspect network ports
๐ง Bonus: Serve Your Full Website
You can upload your entire website (HTML, CSS, JS files) into /usr/share/nginx/html
using:
scp -i your-key.pem index.html ec2-user@<your-ec2-ip>:/usr/share/nginx/html
Or use Git or S3 to download files directly inside EC2.
๐ Conclusion
Thatโs it! You just launched your first static website using Nginx on AWS EC2 โ no Docker or complicated tools. This method is fast, beginner-friendly, and powerful.
Subscribe to my newsletter
Read articles from Poonam Vetal directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Poonam Vetal
Poonam Vetal
I am student from Pune institute of computer technology !๐