This project demonstrates deploying a Node.js web application hosted on a cloud-based AWS EC2 instance, with Nginx acting as a reverse proxy, ensuring high performance and security. The primary goal is to build, deploy, and serve a Node.js server on EC2, making it accessible via a domain or public IP.
- Launch an EC2 Instance and configure security.
- Install Node.js and dependencies.
- Deploy the Node.js application.
- Configure Nginx as a reverse proxy for the Node.js server.
Node.js (Backend runtime)
- Express.js (Web framework)
- PM2 (Background process manager)
- Nginx (Reverse proxy)
- Amazon Linux / CentOS
Once deployed, you can access the app via:
http://<your-server-ip>:3000→ Node app directlyhttp://<your-server-ip>/→ Nginx reverse-proxy
- In the AWS Management Console, in the search bar at the top, enter EC2 and select EC2 under services.
- In the left menu, click on Launch Instances.
- Choose:
-
- AMI: Amazon Linux 2 (recommended)
-
- Key pair: Create new or use existing
-
- Security Group: Allow HTTP (port 80) , SSH (port 22) and allow custom TCP (port 3000) for Node app
- Click Launch to create the instance.
bash
- sudo yum install nodejs -y
- sudo yum install npm -y
bash
- mkdir nodeapp
- cd nodeapp
bash
bash
bash
- npm install
bash
-
systemctl npm start
-
Open browser: http://:3000
bash
- sudo npm install -g pm2
- pm2 start app.js
bash
- sudo yum install nginx -y
- sudo systemctl start nginx
- sudo systemctl enable nginx
- sudo systemctl status nginx
bash
- sudo vim /etc/nginx/nginx.conf
- add the server block inside nginx.con
- nginx.conf
bash
- sudo systemctl restart nginx
bash
- Final Output
- Visit: http:// your-ec2-ip
You should see:
Hello this is nodejs application running on Docker Container!
This guide shows how to deploy a Node.js app on AWS EC2, install necessary tools, run the app with PM2, and set up Nginx as a reverse proxy for secure, accessible web hosting.





