As always, make sure the server is up to date before we start.
apt update
apt upgrade
Install NodeJS from the default package manager repos. The version may be old, If you need a differnt version check out this link https://github.com/nodesource/distributions
Use git to clone your project to /var/www
and install any dependance with npm install
Before moving on, make sure you have set everything up for your project and have tested it.
We will create a system d service to run the node app and keep it running.
[Unit]
Description=web proxy service
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=root
ExecStart=/usr/bin/env node /var/www/proxy/nodejs/bin/www
[Install]
WantedBy=multi-user.target
Edit the Description
and ExecStart
path to match the current NodeJS app.
Save it to /etc/systemd/system/{{name}}.service
. Replace "name" with what you want to name the service. Use only lowercase letters, numbers and dases
Start the service and make sure you can acess it and it works.
systemctl start {{nam}}.service
You can see the stats of a service by running
service {{name}} status
Once you are sure the service is starting the app correctly, enable it(make it start on boot).
systemctl enable proxy.service
# socket.io conf
RewriteEngine On
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule .* ws://localhost:3000%{REQUEST_URI} [P]
RewriteCond %{REQUEST_URI} ^/socket.io/$1/websocket [NC]
RewriteRule socket.io/(.*) ws://localhost:3000/socket.io/$1 [P,L]
ProxyPass /socket.io http://localhost:3000/socket.io
ProxyPassReverse /socket.io http://localhost:3000/socket.io