Page 1 of 1

NodeJS nginx templates

Posted: Tue Apr 13, 2021 7:54 pm
by myVesta
You can install npm-nodejs-pm2 just the way you do in classic way.
If you nerer installed it previously, you can check classic tutorials for Debian - https://www.google.com/search?q=nodejs+ ... +debian+10
Only important things is that you should just skip nginx configuring, since we will do that via the following templates.

Once you run simple nodejs app on port 3000, you can find nodejs nginx templates here :arrow: https://github.com/myvesta/vesta/tree/m ... -templates - simply download these files to /usr/local/vesta/data/templates/web/nginx/ folder.

Alternatively you can use this command to copy all nodejs-nginx-templates to your /usr/local/vesta/data/templates/web/nginx/ folder:

Code: Select all

v-update-myvesta
cp /usr/local/vesta/src/deb/for-download/tools/nodejs-nginx-templates/* /usr/local/vesta/data/templates/web/nginx/
There you have few different templates:
  • node-app-3000 = probably most universal template for nodejs apps, will always redirect visitors to https
  • node-app-3000-no-https-force = the same as previous but without redirecting visitors to https
  • node-app-3000-pass-to-https = will communicate with nodejs app via https connection (if you want SSL encrypted connection between nginx and your nodejs app)
  • node-app-also-handle-static-files-3000 = nginx will not serve static files with this template, requests for static files will be forwarded to nodejs app (for all nodejs apps that needs its own serving of static files, useful for NextJS apps for example)
  • node-app-4000-and-websocket-6001 = the same as first template, but all requests to /app/ folder will be proxied to websocket on port 6001
All templates will try to reach your nodejs app on localhost port 3000.
If you have another apps on different ports, simply make new template (using one of these templates) and just (by editing your new template) change '3000' to some new port, for example '3001'. Here you can see how to achieve that: viewtopic.php?f=20&t=628

P.S. If you want to use these templates in apache-less myVesta installations (installed myVesta without Apache, just nginx installed), then replace ports in template:

Code: Select all

sed -i "s#%proxy_port%#%web_port%#g" /usr/local/vesta/data/templates/web/nginx/node-app-3000.tpl
sed -i "s#%proxy_ssl_port%#%web_ssl_port%#g" /usr/local/vesta/data/templates/web/nginx/node-app-3000.stpl

Re: NodeJS nginx templates

Posted: Tue Nov 09, 2021 7:20 am
by webdoktoru
Sorry if there is any other issue: Nodejs installation

Code: Select all

sudo apt-get install curl software-properties-common 
curl -sL https://deb.nodesource.com/setup_16.x | sudo bash - 

sudo apt-get install nodejs
after

If you want nodejs to be active in the background all the time. i prefer like this:

Code: Select all

npm install -g pm2

//and then use

pm2 start server.js

//to list and stop apps, use commands

pm2 list

pm2 stop 0 
server.js is your index file in your web directory.
like

Code: Select all

pm2 start /home/admin/web/yourdomain.com/public_html/server.js