logico / vestacp-nodejs

Run automatically Node.JS apps in VestaCP.
114 stars 68 forks source link
nginx nodejs vestacp vestacp-templates

VestaCP 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.

VestaCP

Instalation

Auto "With Script":

Manually:

WHERE DEPLOY MY APP?

In VestaCp the user must be a enabled bash ssh, if set as none this si a cause to stack. 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.

In your package.json you can specify your index file with

    ...
    "main": "index.js",
    ...

In your index.js you need run the express server or http with this parameters:

    ...
    //PORT IS PARSET WITH ENV VARIABLE FOR PROPER RUN IF YOU DON'T SET YOUR APP IS CRASH OR NOT RUN!!
    app.listen(process.env.PORT); 
    ...

When your app is launched script create UNIX socket file in /home/<user>/web/<domain>/nodeapp/app.sock is set with 0777 permisses for allow access to NGINX.

DEBUG

Each launch will be copied two logs files <domain-name>-error.log and <domain-name>-out.log to the nodeapp folder.

BLANK PAGES "NODE DOWN"

When your app is down create simply html file in public folder /home/<user>/web/<domain>/public_app/index.html.

FAQ

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

Documentation

Pm2: [https://pm2.keymetrics.io/docs/usage/quick-start/] Info about NGINX Proxy [https://serverfault.com/questions/316157/how-do-i-configure-nginx-proxy-pass-node-js-http-server-via-unix-socket]