Deploying Applications on AWS EC2 (Ubuntu & Windows) - Cover Image

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.

Share on

Save as

0 Comments

Leave a comment

Please login to leave a comment.

Our Mission

At Linux Bro, we are passionate about empowering tech enthusiasts through quality tutorials and educational content. Our mission is to make technology accessible to everyone, regardless of their skill level. We believe in the power of knowledge sharing and strive to create a friendly community where learners can grow, innovate, and succeed together.