π§Ύ 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.pem
andyour-ec2-public-ip
with 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.html
file:
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.