DEV Community

Deep Bag
Deep Bag

Posted on

COMPLETE CONFIGRATION NODE + MONGODB + AWS + DOMAIN + SUBDOMAIN | HOST API SERVER!

Image description

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!

  1. sudo apt update
  2. sudo apt upgrade
  3. sudo apt install nodejs
  4. sudo apt install npm
  5. sudo apt install git
  6. sudo apt install nginx
  7. Install mongodb OFFICIAL WEBSITE
  8. 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
Enter fullscreen mode Exit fullscreen mode

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 ]
Enter fullscreen mode Exit fullscreen mode

>> 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 ]
Enter fullscreen mode Exit fullscreen mode

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:

Enter fullscreen mode Exit fullscreen mode
server {
    listen 80;
    server_name <DOMAIN OR SUBDOMAIN NAME>;

    location / {
       proxy_pass http://127.0.0.1:<BACKEND-PORT>;
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)