NodeJS nginx templates
NodeJS nginx templates
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
https://github.com/myvesta/vesta/tree/m ... -templates - simply download these files to /usr/local/vesta/data/templates/web/nginx/ folder.
There you have few different templates:
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'.
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:
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

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
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'.
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
Tags:
-
- Posts: 1
- Joined: Sat Dec 05, 2020 6:10 am
Re: NodeJS nginx templates
Sorry if there is any other issue: Nodejs installation
after
If you want nodejs to be active in the background all the time. i prefer like this:
server.js is your index file in your web directory.
like
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
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
like
Code: Select all
pm2 start /home/admin/web/yourdomain.com/public_html/server.js