Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions NodeJS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ home=$4
docroot=$5

#default script name
mainScript="app.js"
mainScript="src/index.js"
nodeDir="$home/$user/web/$domain/nodeapp"

mkdir $nodeDir
Expand All @@ -30,14 +30,13 @@ if [ -d "$nvmDir" ]; then

echo "Needs Node version: $nodeVersion"

export NVM_DIR="/opt/nvm/"
source "$NVM_DIR/nvm.sh"
export NVM_DIR=$nvmDir
. "$NVM_DIR/nvm.sh"

if [ ! -d "/opt/nvm/versions/node/$nodeVersion" ]; then
echo "Install this version"
nvm install $nodeVersion

chmod -R 777 /opt/nvm
chmod -R 755 /opt/nvm
else
echo "Error on install Node version on NVM"
fi
Expand Down Expand Up @@ -77,7 +76,7 @@ runuser -l $user -c "pm2 del $scriptName"
#apply enviroment variables from .env file
if [ -f "$nodeDir/.env" ]; then
echo ".env file in folder, applying."
envFile=$(grep -v '^#' $nodeDir/.env | xargs | sed "s/(PORT=(.*) )//g")
envFile=$(grep -v '^#' $nodeDir/.env | xargs | sed "s/(PORT=(.*) )//g" | sed "s/ = /=/g")
echo $envFile
fi

Expand All @@ -90,7 +89,7 @@ sleep 5

if [ ! -f "$nodeDir/app.sock" ]; then
echo "Allow nginx access to the socket $nodeDir/app.sock"
chmod 777 "$nodeDir/app.sock"
chmod 755 "$nodeDir/app.sock"
else
echo "Sock file not present disable Node app"
runuser -l $user -c "pm2 del $scriptName"
Expand All @@ -100,4 +99,4 @@ fi
#copy pm2 logs to app folder
echo "Copy logs to nodeapp folder"
cp -r $home/$user/.pm2/logs/$domain-error.log $nodeDir
cp -r $home/$user/.pm2/logs/$domain-out.log $nodeDir
cp -r $home/$user/.pm2/logs/$domain-out.log $nodeDir
8 changes: 7 additions & 1 deletion NodeJS.stpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ server {
gzip_buffers 4 32k;
gzip_types image/svg+xml svg svgz text/plain application/x-javascript text/xml text/css;
gzip_vary on;

include %home%/%user%/conf/web/%domain%/nginx.hsts.conf*;

location / {

Expand Down Expand Up @@ -65,6 +67,10 @@ server {
location ~ /\.git/ {return 404;}
location ~ /\.hg/ {return 404;}
location ~ /\.bzr/ {return 404;}
location ~ /\.(?!well-known\/|file) {
deny all;
return 404;
}

include %home%/%user%/conf/web/s%proxy_system%.%domain%.conf*;
include %home%/%user%/conf/web/%domain%/nginx.ssl.conf_*;
}
10 changes: 8 additions & 2 deletions NodeJS.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
server {
listen %ip%:%proxy_port%;
server_name %domain_idn% %alias_idn%;

include %home%/%user%/conf/web/%domain%/nginx.forcessl.conf*;

error_log /var/log/%web_system%/domains/%domain%.error.log error;

Expand Down Expand Up @@ -38,7 +40,11 @@ server {
location ~ /\.git/ {return 404;}
location ~ /\.hg/ {return 404;}
location ~ /\.bzr/ {return 404;}
location ~ /\.(?!well-known\/|file) {
deny all;
return 404;
}

include %home%/%user%/conf/web/nginx.%domain%.conf*;
include %home%/%user%/conf/web/%domain%/nginx.conf_*;

}

23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
# VestaCP with Node.JS support.
# HestiaCP with Node.JS support.

With this repo you can run multiples NodeJs Apps at some time.
This template read `.env` file, `.nvm` for Node version, and `package.json` for get info and auto install modules.
With this repo you can run multiples NodeJS Apps at same time.
This template reads the `.env` file, `.nvm` for Node version, and `package.json` to get info and automatically install modules.

![VestaCP](https://logico.com.ar/img/2019/04/21/vestacp_proxy_setup.png)
![HestiaCP](https://logico.com.ar/img/2019/04/21/vestacp_proxy_setup.png)

## Instalation
## Spanish Explication
https://logico.ar/blog/2019/04/20/soporte-para-aplicaciones-nodejs-en-vestacp

## Installation

***Auto "With Script":***
* First download this Git in your `home` directory and run `chmod +x ./install.sh`, `./install.sh`. Script auto install `NVM` and `PM2`
* First download this Git in your `home` directory and run `chmod +x ./install.sh`, `sudo ./install.sh`. Script auto install `NVM` and `PM2`

***Manually:***
* Install PM2 `npm i pm2@latest -g`
* Install NVM see [https://nvm.sh]
* Upload `NodeJS.tpl`, `NodeJS.stpl`, `NodeJS.sh` to `/usr/local/vesta/data/templates/web/nginx/`
* Upload `NodeJS.tpl`, `NodeJS.stpl`, `NodeJS.sh` to `/usr/local/hestia/data/templates/web/nginx/`

## WHERE DEPLOY MY APP?

In VestaCp the user must be a enabled `bash` ssh, if set as `none` this si a cause to stack.
In HestiaCP the user must be a enabled `bash` ssh, if set as `none` this is a cause to stuck.
Upload your app with ssh on this path: `/home/<user>/web/<domain>/nodeapp/`.
Here you can use files `.env` with Enviroment variables, `.nvm` or `.node-version` for specify NodeJs version.
Here you can use files `.env` with Enviroment variables, `.nvm` or `.node-version` for specify NodeJS version.

In your `package.json` you can specify your index file with
```js
Expand Down Expand Up @@ -53,7 +56,7 @@ When your app is down create simply html file in public folder `/home/<user>/web

### Samples

For debug propose you can run script with this arguments `NodeJS.sh <user> <domain> 127.0.0.1 /home` full command: `/usr/local/vesta/data/templates/web/nginx/NodeJS.sh admin default 127.0.0.1 /home`
For debug propose you can run script with this arguments `NodeJS.sh <user> <domain> 127.0.0.1 /home` full command: `/usr/local/hestia/data/templates/web/nginx/NodeJS.sh admin default 127.0.0.1 /home`

* ***Remove all instances***: `runuser -l <user> -c "pm2 del all"` for admin `runuser -l admin -c "pm2 del all"`
* ***List all instances***: `runuser -l <user> -c "pm2 list"` for admin `runuser -l admin -c "pm2 list"`
Expand Down
8 changes: 4 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ if ! command -v pm2 &>/dev/null; then
fi

if [ ! -f ~/.nvm/nvm.sh ]; then
# May need to be updated with the latest nvm release
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Get the latest nvm release
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash


mv ~/.nvm /opt/nvm
chmod -R 777 /opt/nvm
chmod -R 755 /opt/nvm

echo "-> Add this lines to the end your ~/.bashrc file"
echo 'export NVM_DIR="/opt/nvm"
Expand All @@ -24,4 +24,4 @@ fi



cp -R ./NodeJS.* /usr/local/vesta/data/templates/web/nginx/
cp -R ./NodeJS.* /usr/local/hestia/data/templates/web/nginx/
6 changes: 3 additions & 3 deletions sample/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "some-name",
"name": "NodeJS Sample App",
"version": "1.0.0",
"description": "Sample",
"main": "index.js",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "npm run dev"
},
"keywords": [
"211",
"vesta",
"hestia",
"node",
"mp2"
],
Expand Down
File renamed without changes.