How to Configure Nginx and Reverse Proxy to Serve a Static Webpage
1️⃣ Launch EC2 Free Tier Instance
- Chose default VPC and default subnet
- Enabled Auto-assign Public IP (required for SSH & HTTP access)
- Created a security group with inbound rules:
- SSH (port 22) → My IP only
- HTTP (port 80) → Anywhere (0.0.0.0/0)
- Outbound rules: allow all (default, fine for updates)
2️⃣ SSH into EC2 Instance
- Set proper permissions for the
.pemkey:
chmod 400 ~/DevOps.pem
- Connected using the correct username (depends on AMI):
- Amazon Linux → ec2-user
- Ubuntu → ubuntu
ssh -i ~/DevOps.pem ec2-user@YOUR_PUBLIC_IP
- If you get Permission denied, check:
- Correct username for your AMI
- .pem file permissions
3️⃣ Update the EC2 Instance
sudo yum update -y
4️⃣ Install Nginx
sudo yum install nginx -y
- Start & enable Nginx:
sudo systemctl start nginx
sudo systemctl enable nginx
5️⃣ Copy Local Files to EC2
- From WSL, copied a folder or file to EC2:
scp -i ~/DevOps.pem -r ~/DevOps ec2-user@YOUR_PUBLIC_IP:/home/ec2-user/
-
-r→ recursive, copies entire folder including subfolders
6️⃣ Move Files to Nginx Root
Nginx serves files from its root directory:
Move folder into Nginx root:
sudo mv ~/DevOps /usr/share/nginx/html/
- Folder structure after move:
/usr/share/nginx/html/DevOps/index.html
7️⃣ Fix Permissions
sudo chmod -R 755 /usr/share/nginx/html/DevOps
8️⃣ Test Your Site
- From EC2 itself:
curl http://localhost/DevOps/index.html
✅ Outcome
EC2 instance is updated and running
Nginx is installed, started, and enabled on boot
Your folder DevOps is served by Nginx publicly
Permissions are correct — files are accessible without exposing the server unnecessarily
Top comments (0)