NodeJS & Python Web, Script

Please Provide proper tutorials on NodeJS & Python Web/Script setup. or auto setup

not planed from dev side, feel free to help out with our docs.

How to Use Node.js in HestiaCP

By default, HestiaCP does not include support for publishing applications developed under Node.js, but you can easily set up your server to work with Node.js applications. Follow these steps to publish an application using HestiaCP either under app.sock or by listening on port 3000.

Installing Node.js:
HestiaCP’s pre-installed image already comes with Node.js, but you’ll need to install npm to manage your Node.js applications. Execute the following command:

# apt install npm

Creating templates for Nginx using port 3000:
To publish Node.js applications, we’ll use Nginx as a proxy to redirect requests arriving at port 80 to port 3000 where Node.js is running. Perform the following steps to create the necessary files and set the correct permissions:

# touch /usr/local/hestia/data/templates/web/nginx/nodejs3000.sh
# touch /usr/local/hestia/data/templates/web/nginx/nodejs3000.tpl
# touch /usr/local/hestia/data/templates/web/nginx/nodejs3000.stpl

# chmod 755 /usr/local/hestia/data/templates/web/nginx/nodejs3000.sh
# chmod 755 /usr/local/hestia/data/templates/web/nginx/nodejs3000.tpl
# chmod 755 /usr/local/hestia/data/templates/web/nginx/nodejs3000.stpl

Add the following code to the nodejs3000.sh file:

#!/bin/bash
user=$1
domain=$2
ip=$3
home=$4
docroot=$5

mkdir "$home/$user/web/$domain/nodeapp"
chown -R $user:$user "$home/$user/web/$domain/nodeapp"
rm "$home/$user/web/$domain/nodeapp/app.sock"
runuser -l $user -c "pm2 start $home/$user/web/$domain/nodeapp/app.js"
sleep 5
chmod 777 "$home/$user/web/$domain/nodeapp/app.sock"

Add the following code to the nodejs3000.tpl file:

server {
    listen %ip%:%proxy_port%;
    server_name %domain_idn% %alias_idn%;
    error_log /var/log/%web_system%/domains/%domain%.error.log error;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /error/ {
        alias %home%/%user%/web/%domain%/document_errors/;
    }

    location @fallback {
        proxy_pass http://127.0.0.1:3000:/$1;
    }

    location ~ /\.ht {
        return 404;
    }
    location ~ /\.svn/ {
        return 404;
    }
    location ~ /\.git/ {
        return 404;
    }
    location ~ /\.hg/ {
        return 404;
    }
    location ~ /\.bzr/ {
        return 404;
    }

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

Add the following code to the nodejs3000.stpl file:

server {
    listen %ip%:%proxy_port%;
    server_name %domain_idn%;
    return 301 https://%domain_idn%$request_uri;
}

server {
    listen %ip%:%proxy_ssl_port% http2 ssl;
    server_name %domain_idn%;
    ssl_certificate %ssl_pem%;
    ssl_certificate_key %ssl_key%;
    error_log /var/log/%web_system%/domains/%domain%.error.log error;
    gzip on;
    gzip_min_length 1100;
    gzip_buffers 4 32k;
    gzip_types image/svg+xml svg svgz text/plain application/x-javascript text/xml text/css;
    gzip_vary on;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /error/ {
        alias %home%/%user%/web/%domain%/document_errors/;
    }

    location @fallback {
        proxy_pass https://127.0.0.1:3000:/$1;
    }

    location ~ /\.ht {
        return 404;
    }
    location ~ /\.svn/ {
        return 404;
    }
    location ~ /\.git/ {
        return 404;
    }
    location ~ /\.hg/ {
        return 404;
    }
    location ~ /\.bzr/ {
        return 404;
    }

    include %home%/%user%/conf/web/s%proxy_system%.%domain%.conf*;
}

Creating templates for Nginx using the app.sock socket:
Alternatively, you can redirect requests arriving at port 80 to Node.js using a socket named app.sock. Follow these steps to create the necessary files and set the correct permissions:

# touch /usr/local/hestia/data/templates/web/nginx/nodejssock.sh
# touch /usr/local/hestia/data/templates/web/nginx/nodejssock.tpl
# touch /usr/local/hestia/data/templates/web/nginx/nodejssock.stpl

# chmod 755 /usr/local/hestia/data/templates/web/nginx/nodejssock.sh
# chmod 755 /usr/local/hestia/data/templates/web/nginx/nodejssock.tpl
# chmod 755 /usr/local/hestia/data/templates/web/nginx/nodejssock.stpl

Add the following code to the nodejssock.sh file:

#!/bin/bash
user=$1
domain=$2
ip=$3
home=$4
docroot=$5

mkdir "$home/$user/web/$domain/nodeapp"
chown -R $user:$user "$home/$user/web/$domain/nodeapp"
rm "$home/$user/web/$domain/nodeapp/app.sock"
runuser -l $user -c "pm2 start $home/$user/web/$domain/nodeapp/app.js"
sleep 5
chmod 777 "$home/$user/web/$domain/nodeapp/app.sock"

Add the following code to the nodejssock.tpl file:

server {
    listen %ip%:%proxy_port%;
    server_name %domain_idn% %alias_idn%;
    error_log /var/log/%web_system%/domains/%domain%.error.log error;

    location / {
        proxy_pass http://unix:%home%/%user%/web/%domain%/nodeapp/app.sock:$request_uri;
        location ~* ^.+\.(%proxy_extentions%)$ {
            root %docroot%;
            access_log /var/log/%web_system%/domains/%domain%.log combined;
            access_log /var/log/%web_system%/domains/%domain%.bytes bytes;
            expires max;
            try_files $uri @fallback;
        }
    }

    location /error/ {
        alias %home%/%user%/web/%domain%/document_errors/;
    }



    location @fallback {
        proxy_pass http://unix:%home%/%user%/web/%domain%/nodeapp/app.sock:/$1;
    }

    location ~ /\.ht {
        return 404;
    }
    location ~ /\.svn/ {
        return 404;
    }
    location ~ /\.git/ {
        return 404;
    }
    location ~ /\.hg/ {
        return 404;
    }
    location ~ /\.bzr/ {
        return 404;
    }

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

Add the following code to the nodejssock.stpl file:

server {
    listen %ip%:%proxy_port%;
    server_name %domain_idn%;
    return 301 https://%domain_idn%$request_uri;
}

server {
    listen %ip%:%proxy_ssl_port% http2 ssl;
    server_name %domain_idn%;
    ssl_certificate %ssl_pem%;
    ssl_certificate_key %ssl_key%;
    error_log /var/log/%web_system%/domains/%domain%.error.log error;
    gzip on;
    gzip_min_length 1100;
    gzip_buffers 4 32k;
    gzip_types image/svg+xml svg svgz text/plain application/x-javascript text/xml text/css;
    gzip_vary on;

    location / {
        proxy_pass http://unix:%home%/%user%/web/%domain%/nodeapp/app.sock:$request_uri;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_set_header X-NginX-Proxy true;
        location ~* ^.+\.(%proxy_extentions%)$ {
            root %sdocroot%;
            access_log /var/log/%web_system%/domains/%domain%.log combined;
            access_log /var/log/%web_system%/domains/%domain%.bytes bytes;
            expires max;
            try_files $uri @fallback;
            add_header Pragma public;
            add_header Cache-Control "public";
        }
    }

    location /error/ {
        alias %home%/%user%/web/%domain%/document_errors/;
    }

    location @fallback {
        proxy_pass http://unix:%home%/%user%/web/%domain%/nodeapp/app.sock:/$1;
    }

    location ~ /\.ht {
        return 404;
    }
    location ~ /\.svn/ {
        return 404;
    }
    location ~ /\.git/ {
        return 404;
    }
    location ~ /\.hg/ {
        return 404;
    }
    location ~ /\.bzr/ {
        return 404;
    }

    include %home%/%user%/conf/web/s%proxy_system%.%domain%.conf*;
}

Using templates in the HestiaCP panel:
To connect to your HestiaCP panel, access https://host_name:8083 with the username “admin” and the password provided in the client panel.

Once inside the Hestia panel, go to “WEB” and click on the domain where you want to use the Node.js template.

  1. In the “NGINX Proxy Support” section, click on the dropdown that shows “default” (the default option) and select either “nodejs3000” or “nodejssock” depending on your project’s requirements.

Example: Starting a Node.js project in HestiaCP:
For this example, we will use a sample project from “contentful.com,” which can be found on GitHub.

  1. In the HestiaCP panel, edit your web domain and select the “nodejs3000” template, then save the configuration. This will automatically set up the configuration for Nginx and create the directory “/home/admin/web/domain_name/nodeapp.”

  2. To start the example project, execute the following commands:

# cd /tmp
# git clone https://github.com/contentful/the-example-app.nodejs.git
# cd the-example-app.nodejs/
# mv .* /home/admin/web/domain_name/nodeapp
# mv * /home/admin/web/domain_name/nodeapp
# cd /home/admin/web/domain_name/nodeapp
# cd ..
# chown -R admin.admin nodeapp/
# find nodeapp/ -type f -exec chmod 644 {} ";"
# find nodeapp/ -type d -exec chmod 755 {} ";"
# cd nodeapp
# npm install
# npm run start:dev

Now, the application is running on port 3000, and if you access it, you should see the application’s output.

Please note that the links provided in the example are placeholders and may not be functional. Be sure to replace them with your actual domain and paths.

6 Likes

nodejs3000 template work for 3000 port only, right?

for another port website i have to create another template!!!?

another, Q is where i can use nodejssock template?

See:

Yes you need to create a template for each unique port

edit web, choose template…

I’m not using Apache, and when add all Configuration in my Web Template (nginX) NodeJS not showing, i’ve Laravel Project
Is need to change /usr/local/hestia/data/templates/web/nginx/ to /usr/local/hestia/data/templates/web/nginx//php-fpm to Install NodeJS on only for nginX???
or /usr/local/hestia/data/templates/web/nginx/ is fine?
is this working on my Laravel Project with Select Laravel Template???

Yes you also need to update your template to include web port instead of proxy port…

1 Like

You can use mode express to use several apps in the same port.

You can see the example 2 in the following website to configure your apps:

how to use express with hestiacp?

same way, you can reverse DNS or Other templates

thank you,

i have created a script that modifies quick installs and adds proper nodejs support, also adds v-install-node in /usr/local/hestia/bin if anyone is interested drop your email ill send it.

1 Like

if you have any valuable thing to add to hestiacp, please create a pull request on the github page: https://github.com/hestiacp/hestiacp

1 Like

I posted a similar question in the following article 3 days ago but did not get any answer.
I don’t need to change the port for the web, I just need to run a separate service included with the script in order to speed up real-time messages and notifications.
Would respected members please take a look and provide assistance in clarifying how to configure this?

Hola, buen dĂ­a Âżpuedes enviarme el archivo para soportar NodeJS en HestiaCP? (v-install-node)

A cualquiera de estas dos direcciones e-mail:

[email protected]

[email protected]

Gracias de antemano…

I have added, but templates is not showing up, at panel.
Proxy Templates list missing!
any suggestions?


You have NGINX only template you need upload it to /usr/local/hestia/data/templates/web/nginx/php-fpm and make some changes the templates…

what changes i have to do, as per this solution

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.