-
Notifications
You must be signed in to change notification settings - Fork 1
Setting up a production server
This document describes how CausalPath webserver can be run in a production environment using PM2 and Nginx. We highly benefited from this guide during the preparation of this document.
Follow the guidelines in the README to download and run the app in the environment that the server will be hosted.
These instructions are tested on a VM with Ubuntu 20.04.
Assuming the server code is checked out to
/home/sammy/Code/causalpath-newt-webserver
and it is your current directory. sammy
is your username.
You have node version 14 installed under
/home/sammy/.nvm
The server runs fine with the below command
npm start
Now, stop the server with Ctrl+C and follow the below steps.
npm install pm2@latest -g
pm2 start npm --name CausalPath -- start
Make sure the server is running without problems after this command.
pm2 save
Type
pm2 startup systemd
This will print a message on the shell similar to the below.
[PM2] Init System found: systemd
[PM2] To setup the Startup Script, copy/paste the following command:
sudo env PATH=$PATH:/home/sammy/.nvm/versions/node/v14.20.0/bin /home/sammy/.nvm/versions/node/v14.20.0/lib/node_modules/pm2/bin/pm2 startup systemd -u sammy --hp /home/sammy
Copy and paste the last line (it will have your user name instead of sammy
, and maybe other differences) on the shell.
sudo env PATH=$PATH:/home/sammy/.nvm/versions/node/v14.20.0/bin /home/sammy/.nvm/versions/node/v14.20.0/lib/node_modules/pm2/bin/pm2 startup systemd -u sammy --hp /home/sammy
sudo apt update
sudo apt install nginx
Type
sudo ufw app list
This will print available application profiles such as
Available applications:
Nginx Full
Nginx HTTP
Nginx HTTPS
OpenSSH
Allow HTTP by typing
sudo ufw allow 'Nginx HTTP'
Check if Nginx is up and running by
systemctl status nginx
Edit the file
/etc/nginx/sites-available/default
to make sure the location
block has the below content
server {
...
location / {
proxy_pass http://localhost: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;
}
...
}
Make sure you didn't introduce any error after the edit by typing
sudo nginx -t
Restart Nginx by
sudo systemctl restart nginx
After this operation, you should be able to access CausalPath webserver through port 80.
Reboot the system by
sudo systemctl reboot -i
and see if the server starts up automatically.