How to install System E-Card
- Use Node.js and Express.js with Nginx on a VM using GitHub to deployment
- How to apply HTTPS or SSL to System
- VM Use In E-Card
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
-
How to apply HTTPS or SSL to System
1.If enable HTTPS with Certbot
-
Install Certbot:
-
sudo apt install certbot python3-certbot-nginx -y
-
-
Obtain an SSL certificate:
-
sudo certbot --nginx -d verify.rupp.edu.kh
-
2. If use own Certificate
- Make folder letsencrypt-rupp into /etc and past file certificates_rupp.
- And replace this code in nginx
-
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 443 ssl; # managed by itc ssl_certificate /etc/letsencrypt-rupp/certificates_rupp/rupp.edu.kh.crt; # managed by itc ssl_certificate_key /etc/letsencrypt-rupp/certificates_rupp/rupp.edu.kh.key; # managed by itc } server { if ($host = verify.rupp.edu.kh) { return 301 https://$host$request_uri; } # managed by itc server_name verify.rupp.edu.kh; listen 80; return 404; # managed by itc }
-
VM Use In E-Card
172.17.20.23 use for domain verify.rupp.edu.kh
172.17.20.24 use for domain staff-system.rupp.edu.kh