Deploying Applications on AWS EC2 (Ubuntu & Windows)
Let’s start.
π PART 1: Launching an EC2 Instance (Ubuntu)
1οΈβ£ Open EC2 Dashboard
-
Login to AWS Console
-
Go to Services → EC2
-
Click Launch Instances
2οΈβ£ Configure Instance Details
-
Name: ubuntu-production / ubuntu-staging etc.
-
AMI:
β Ubuntu Server 22.04 LTS (recommended) -
Instance type: t2.micro / t3.micro
-
Key pair:
β Create new → download PEM file
β Store the PEM safely; you cannot download it again.
3οΈβ£ Configure Network & Security Group
-
Choose default VPC
-
Under Security Group, add:
| Type | Port | Description |
|---|---|---|
| SSH | 22 | For PEM login |
| HTTP | 80 | For NGINX websites |
| HTTPS | 443 | SSL |
| Custom (optional) | 3000/8000/5000 | App server ports |
Use My IP for SSH for security.
4οΈβ£ Launch the instance
Wait until the instance state becomes Running.
π PART 2: Connect to Ubuntu EC2 using PEM File
1οΈβ£ Set permissions on PEM
From your local machine:
chmod 400 my-server.pem
2οΈβ£ Connect using SSH
ssh -i my-server.pem ubuntu@<PUBLIC_IP>
If you see:
Are you sure you want to continue connecting (yes/no)?
Type yes.
You are now inside your Ubuntu EC2 machine.
π PART 3: Install NGINX on Ubuntu
Update packages:
sudo apt update && sudo apt upgrade -y
Install NGINX:
sudo apt install nginx -y
Start & enable:
sudo systemctl start nginx sudo systemctl enable nginx
sudo systemctl status nginx
Visit:
http://<EC2-PUBLIC-IP>
You should see “Welcome to nginx!”
π PART 4: Pulling Code to EC2 (GitHub)
Install git:
sudo apt install git -y
Clone your repo:
git clone https://github.com/<username>/<repo>.git
Or pull updates:
βββββββgit pull origin main
Move into your project:
cd repo-name
π PART 5: Run Your Backend Service
Depending on your application stack:
β For Django (Gunicorn)
pip install gunicorn gunicorn --bind 0.0.0.0:8000 projectname.wsgi:application
β For Node.js
npm install node server.js
β For Flask
gunicorn -w 4 -b 0.0.0.0:5000 app:app
Your app will now be running on a port like 8000 / 5000 / 3000.
π PART 6: Configure NGINX Reverse Proxy (Ubuntu)
Create a new nginx config file:
sudo nano /etc/nginx/sites-available/myproject
Paste the reverse proxy configuration:
server { listen 80; server_name _; location / { proxy_pass http://127.0.0.1:8000; # Change to your app port proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
Save & Exit.
Link config:
sudo ln -s /etc/nginx/sites-available/myproject /etc/nginx/sites-enabled/
Test nginx:
sudo nginx -t
Restart:
sudo systemctl restart nginx
Visit browser:
http://<EC2-PUBLIC-IP>
Your app is live through NGINX.
0 Comments
Leave a comment
Please login to leave a comment.
Popular Posts
Deploying Applications on AWS EC2 (Ubuntu & Windows)
29 Nov, 2025