In this post I can give you complete information about the deploy nodejs api server in aws!
We need to run commands and install packages!
- sudo apt update
- sudo apt upgrade
- sudo apt install nodejs
- sudo apt install npm
- sudo apt install git
- sudo apt install nginx
- Install mongodb OFFICIAL WEBSITE
- sudo npm install pm2
PROCESS TO LIVE
AWS CONFIGRATIONS:
1. LAUNCH EC2 INSTANCES
2. UPDATE SECURITY GROUP - ADD PORT
[ 22, 80, 443, 27017, <BACKEND-PORT> ]
3. GENERATE ELASTIC IP
4. POINT YOUR MAIN DOMAIN TO EC2 PUBLIC IP A RECORD
5. CREATE A SUBDOMAIN THAT NEED TO POINTING A SPECIFIC PORT
EC2 CONFIGRATION:
1. UPDATE NODEJS TO NEWEST LTS VERSION
2. CLONE BACKEND REPO TO [ VAR/WWW/HTML ] PATH
3. START PM2 [ SUDO PM2 START <FILENAME> ]
4. START MONGODB [ SUDO SYSTEMCTL START MONGOD ]
5. START NGINX [ SUDO SYSTEMCTL START NGINX ]
>> ACCESS VIA IP IN YOUR BROWSER
[ EC2 PUBLIC IP EXAMPLE 1.201.10.2 - NGINX MAIN SERVER ]
[ 1.201.10.2:<BACKEND-PORT> - BACKEND SERVER ]
CONFIGURE NGINX FOR POINTING DOMAIN:
1. EDIT NGINX CONFIG FILE [ /ETC/NGINX/SITES-ENABLED/DEFAULT ]
{ COMMAND : SUDO NANO /ETC/NGINX/SITES-ENABLED/DEFAULT }
2. ADD THIS LINES IN YOUR SITE-ENABLES/DEFAULT FILE:
server {
listen 80;
server_name <DOMAIN OR SUBDOMAIN NAME>;
location / {
proxy_pass http://127.0.0.1:<BACKEND-PORT>;
}
}
Top comments (0)