DEV Community

Kew Coder
Kew Coder

Posted on

Simple run Node JS App in VPS Server NginX with SSL

Node Js Nginx Server

apt update && apt upgrade

apt -y install nginx

apt install software-properties-common
add-apt-repository universe
add-apt-repository ppa:certbot/certbot

apt update

apt -y install python-certbot-nginx

nano /etc/nginx/sites-available/domain.com

server {
listen 80;
server_name domain.com;

location / {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

sudo ln -s /etc/nginx/sites-available/domain.com  /etc/nginx/sites-enabled/

sudo ln -s /etc/nginx/sites-available/domain.com /etc/nginx/sites-enabled

sudo nginx -t && sudo systemctl restart nginx

certbot --nginx -d domain.com

sudo apt install nodejs

sudo apt install npm

npm install pm2 -g

pm2 start server.js

run project with pm2 to localhost:8000

Discussion (0)