Host a Website on EC2 With Nginx
Part of the AWS Roadmap
In short
This project ties Linux, networking and EC2 together into something you can open in a browser and show off: your own website, served by Nginx from a server you launched and secured yourself.
A first hands-on project that launches an EC2 instance with a user data script, installs Nginx, serves a simple website and locks down access with security groups. It ties together Linux, networking and EC2 basics.

Think of it like this
Opening a small shop
You rent a shop (instance), the shutter faces the main road (public subnet and IP), you put the goods on display (website files), a shopkeeper serves customers (Nginx) and the back door stays locked (security group). Then customers can walk in.
Watch it happen
A visitor opens your site
HTTP to public IP :80
1/4The browser connects to your instance's public IP on port 80.
The big ideas
What you need to know
User data does the setup
Installing Nginx and copying the site happen at boot, so you can rebuild the server any time.
Only port 80 open
Use Session Manager for admin access so SSH stays closed.
Stable address
Attach an Elastic IP if you want the address to survive a stop and start. Later, a load balancer and domain replace it.
HTTPS next
For HTTPS you would add a certificate, usually through an Application Load Balancer or CloudFront with ACM.
How it works
Project steps
- 1
Security group
Create web-sg allowing TCP 80 from anywhere and nothing else inbound.
- 2
Role
Create an instance role with AmazonSSMManagedInstanceCore for Session Manager.
- 3
Launch
Run a t3.micro with Amazon Linux 2023, the role, web-sg and the user data below.
- 4
Test
Open http://<public-ip> and check the page and the server's AZ.
- 5
Clean up
Terminate the instance and release any Elastic IP when you finish.
See it in code
Walk through the code
1#!/bin/bash2set -euxo pipefail3dnf install -y nginx4 5cat > /usr/share/nginx/html/index.html <<'HTML'6<!doctype html>7<html>8 <head><title>Chai Point Pune</title></head>9 <body>10 <h1>Fresh chai, served from AWS Mumbai</h1>11 <p>Open daily 7 am to 10 pm, FC Road.</p>12 </body>13</html>14HTML15 16systemctl enable --now nginx1/4Install Nginx from the Amazon Linux 2023 repositories.
The whole website setup as user data. Launch with --user-data file://site.sh and the shop opens itself.
Save yourself the pain
Common mistakes
Oops
The page doesn't load, so you open every port to 0.0.0.0/0.
Do this instead
Check in order: instance running, public IP present, subnet routes to an internet gateway, SG allows 80, Nginx is active.
Oops
Using https:// with no certificate configured.
Do this instead
This project serves HTTP only. Use http://, and add HTTPS later with a load balancer or CloudFront.
Your mission
Ship your shop
Quick check
Your site loads but you can no longer SSH in after removing port 22. How do you get a shell without reopening it?
Go deeper
- 1Automate the Nginx install with user data so the site works with no manual SSH steps.
- 2Allow only ports 80 and 443 publicly and SSH from your IP or use Session Manager.
- 3Document the steps with screenshots in a GitHub README, then terminate the instance.
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.