Use Node.js and Express.js with Nginx on a VM using GitHub to deployment
1. Prepare VM
- Update and install necessary packages:
-
sudo apt update && sudo apt upgrade -y sudo apt install git nodejs npm nginx -y
-
- Verify Node.js and npm installation:
-
node -v npm -v
-
- Install a process manager like PM2:
-
sudo npm install -g pm2
-
2. Clone and Set Up Project
3. Configure Nginx as a Reverse Proxy
-
Create an Nginx configuration file for domain:
-
sudo nano /etc/nginx/sites-available/verify.rupp.edu.kh
-
-
Add the following content:
-
server { server_name verify.rupp.edu.kh; location / { proxy_pass http://127.0.0.1:3000; 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; } listen 80; }
-
-
Enable the configuration:
-
sudo ln -s /etc/nginx/sites-available/verify.rupp.edu.kh /etc/nginx/sites-enabled/
-
-
Test Nginx configuration:
-
sudo nginx -t
-
-
Reload Nginx:
-
sudo systemctl reload nginx
-
No Comments