๐งพ Prerequisites
Before we dive in, make sure you have:
- An AWS account
- Basic understanding of EC2
- A key pair (for SSH access)
- A domain name (optional but helpful)
๐ง Step 1: Launch an EC2 Instance
- Go to the AWS EC2 Dashboard.
- Click โLaunch Instanceโ.
- Choose Ubuntu Server 22.04 LTS (or 20.04).
- Select a free-tier eligible type like
t2.micro. - Create or use an existing key pair.
- Under Security Group, allow these:
- SSH (port 22) โ to access your server
- HTTP (port 80) โ for web traffic
- HTTPS (port 443) โ for SSL later
Click โLaunchโ and wait for the instance to be ready.
๐ Step 2: Connect to the Server via SSH
Use your .pem key to SSH into your instance:
ssh -i /path/to/your-key.pem ubuntu@your-ec2-public-ip
Replace
/path/to/your-key.pemandyour-ec2-public-ipwith your actual key file and public IP.
๐ฆ Step 3: Update the Server
Once connected, always update your server packages:
sudo apt update && sudo apt upgrade -y
๐ Step 4: Install NGINX
Letโs install the NGINX web server:
sudo apt install nginx -y
Now start and enable NGINX:
sudo systemctl start nginx
sudo systemctl enable nginx
Check status:
sudo systemctl status nginx
๐ Step 5: (Optional) Allow NGINX Through UFW Firewall
If youโre using UFW (Ubuntuโs firewall):
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status
๐ Step 6: Test in Your Browser
Open your browser and go to:
http://your-ec2-public-ip
You should see the default NGINX welcome page โ that means itโs working! โ
๐ Step 7: Create Your Own Website
Want to serve your own content?
- Create a directory:
sudo mkdir -p /var/www/yourdomain.com
sudo chown -R $USER:$USER /var/www/yourdomain.com
- Add an
index.htmlfile:
echo "<h1>Hello from NGINX on AWS!</h1>" > /var/www/yourdomain.com/index.html
- Create a new NGINX config:
sudo nano /etc/nginx/sites-available/yourdomain.com
Paste:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /var/www/yourdomain.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
- Enable it and reload NGINX:
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
๐ Step 8: Add SSL with Letโs Encrypt (Free HTTPS)
To secure your site with HTTPS:
sudo apt install certbot python3-certbot-nginx -y
Run Certbot:
sudo certbot --nginx
Follow the prompts to install SSL automatically. ๐
โ Final Words
You now have NGINX running on an AWS EC2 instance โ serving your own website, secured with HTTPS.
๐ Summary Checklist
| Task | Status |
|---|---|
| โ Launch EC2 with Ubuntu | โ๏ธ |
| โ Install NGINX | โ๏ธ |
| โ Set up security groups | โ๏ธ |
| โ Deploy a custom site | โ๏ธ |
| โ Enable SSL with Certbot | โ๏ธ |
๐ฌ Need Help?
Drop your questions in the comments.
