Page 1 of 1

New Nginx template not run node.js app

Posted: Thu Jun 17, 2021 6:54 pm
by romienas
Hi,
I'm new with Vesta, and I'm trying to run node.js application. But the main problem that there is no any tutorials how to run node.js applications on Vesta cp.
I find out that I have to create a Nginx template, so I created template and added to domain, but nothing happen and I still can't see my application...
Where is my mistakes?
My templates files content:

.tpl file

Code: Select all

server {
    #listen      %ip%:%proxy_port%;
    listen       194.5.157.109:8086;
    #server_name %domain_idn% %alias_idn%;
    server_name web.com;
    location / {
        proxy_pass http://194.5.157.109:8086;
        rewrite ^(.*) https://%domain_idn%$1 permanent;
    }
include %home%/%user%/conf/web/*nginx.%domain_idn%.conf_letsencrypt;
}
.stpl file

Code: Select all

server {
    listen      %ip%:%proxy_ssl_port%;
    server_name %domain_idn% %alias_idn%;
    ssl         on;
    ssl_certificate      %ssl_pem%;
    ssl_certificate_key  %ssl_key%;
    error_log  /var/log/%web_system%/domains/%domain%.error.log error;

    location / {
        proxy_pass      https://%ip%:%web_ssl_port%;
        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;
        }
    }

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

    location @fallback {
        proxy_pass      https://%ip%:%web_ssl_port%;
    }

    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_idn%.conf_letsencrypt;
    include %home%/%user%/conf/web/s%proxy_system%.%domain%.conf*;
}

Re: New Nginx template not run node.js app

Posted: Wed Jun 23, 2021 3:13 pm
by milesstone
romienas wrote:
Thu Jun 17, 2021 6:54 pm
Hi,
I'm new with Vesta, and I'm trying to run node.js application. But the main problem that there is no any tutorials how to run node.js applications on Vesta cp.
I find out that I have to create a Nginx template, so I created template and added to domain, but nothing happen and I still can't see my application...
Where is my mistakes?
My templates files content:

.tpl file gbwhatsapp

Code: Select all

server {
    #listen      %ip%:%proxy_port%;
    listen       194.5.157.109:8086;
    #server_name %domain_idn% %alias_idn%;
    server_name web.com;
    location / {
        proxy_pass http://194.5.157.109:8086;
        rewrite ^(.*) https://%domain_idn%$1 permanent;
    }
include %home%/%user%/conf/web/*nginx.%domain_idn%.conf_letsencrypt;
}
.stpl file

Code: Select all

server {
    listen      %ip%:%proxy_ssl_port%;
    server_name %domain_idn% %alias_idn%;
    ssl         on;
    ssl_certificate      %ssl_pem%;
    ssl_certificate_key  %ssl_key%;
    error_log  /var/log/%web_system%/domains/%domain%.error.log error;

    location / {
        proxy_pass      https://%ip%:%web_ssl_port%;
        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;
        }
    }

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

    location @fallback {
        proxy_pass      https://%ip%:%web_ssl_port%;
    }

    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_idn%.conf_letsencrypt;
    include %home%/%user%/conf/web/s%proxy_system%.%domain%.conf*;
}
Hmmm all that sounds like it should work…

Just to be clear, this is what your nginx config should look like:

server {
listen 80;
server_name mydomain.com www.mydomain.com;
return 301 https://$host$request_uri;
}

server {
listen 443 ssl;
server_name mydomain.com www.mydomain.com;
ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
location / {
proxy_pass http://localhost:3010;
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;
}
}
and make sure your server.js node app is running on port 3010.

i.e.: in express.js…

const express = require('express');
const app = express();

app.get('/', function (req, res) { res.send('Hello World!')});

app.listen(3010, function() { console.log('Example app listening on port 3010!'); });
Then confirm nginx is running with sudo service nginx status and confirm your node app is running with forever list or check the forever logs with forever logs server.js