diff --git a/NodeJS.sh b/NodeJS.sh index fd35fc8..358c395 100755 --- a/NodeJS.sh +++ b/NodeJS.sh @@ -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 @@ -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 @@ -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 @@ -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" @@ -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 \ No newline at end of file +cp -r $home/$user/.pm2/logs/$domain-out.log $nodeDir diff --git a/NodeJS.stpl b/NodeJS.stpl index e9c0812..19dc02d 100644 --- a/NodeJS.stpl +++ b/NodeJS.stpl @@ -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 / { @@ -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_*; } diff --git a/NodeJS.tpl b/NodeJS.tpl index f56cf8d..3e2f98a 100755 --- a/NodeJS.tpl +++ b/NodeJS.tpl @@ -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; @@ -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_*; + } - diff --git a/README.md b/README.md index cf47194..6866ffa 100644 --- a/README.md +++ b/README.md @@ -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//web//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 @@ -53,7 +56,7 @@ When your app is down create simply html file in public folder `/home//web ### Samples -For debug propose you can run script with this arguments `NodeJS.sh 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 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 -c "pm2 del all"` for admin `runuser -l admin -c "pm2 del all"` * ***List all instances***: `runuser -l -c "pm2 list"` for admin `runuser -l admin -c "pm2 list"` diff --git a/install.sh b/install.sh index d2c6ca0..8d13714 100644 --- a/install.sh +++ b/install.sh @@ -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" @@ -24,4 +24,4 @@ fi -cp -R ./NodeJS.* /usr/local/vesta/data/templates/web/nginx/ \ No newline at end of file +cp -R ./NodeJS.* /usr/local/hestia/data/templates/web/nginx/ diff --git a/sample/package.json b/sample/package.json index ebc1f51..0ec2ab6 100644 --- a/sample/package.json +++ b/sample/package.json @@ -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" ], diff --git a/sample/index.js b/sample/src/index.js similarity index 100% rename from sample/index.js rename to sample/src/index.js