pm2 startup (For automatically running PM2 when the server stop/restarts)
This will output a script in the terminal which you need to run, copy the script that it outputs and run it in the terminal window. Now, save all the currently running processes so that they can be run again whenever PM2 restarts either manually or by a script with the following command:
To remove port no 3000 - we should route 3000 to port 80 - Now lets install NGINX SERVER for that - FOR LINUX ITS DIFFERENT
sudo apt-get update
nginx -v
sudo service nginx start (use sudo service nginx (then command))
service nginx status
CHECK THE URL OF Ec2 it will show NGINX DEFAULT PAGE
PLEASE NOTE : Open PORT 80 in AWS security froup inbound rules - HTTP 3000
NOW OPEN THE NGIX config file and do the below setting (https://www.cyberciti.biz/faq/nginx-linux-restart/, https://www.tecmint.com/nginx-as-reverse-proxy-for-nodejs-app/)
cd /etc/nginx/sites-available
systemctl restart nginx
sudo nano /etc/nginx/nginx.conf
===
server {
listen 80;
server_name 13.127.255.36;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://13.233.237.79/:3000;
}
}
}
===
sudo apt-get remove nginx
sudo systemctl restart nginx (restart nginx)
sudo systemctl status nginx (see nginx status)
sudo systemctl enable nginx (always on after reboot also)