Cannot deploy AdonisJS app on cyberpanel successfully

We searched the forum here and found several examples of how to run a node app on the server. But we were not successful.

We added context at the end of the vhost

Could someone tell us where we could be wrong in our setup?

docRoot $VH_ROOT/public_html
vhDomain $VH_NAME
vhAliases www.$VH_NAME
adminEmails [email protected]
enableGzip 1
enableIpGeo 1

index {
useServer 0
indexFiles index.php, index.html
}

errorlog $VH_ROOT/logs/$VH_NAME.error_log {
useServer 0
logLevel WARN
rollingSize 10M
}

accesslog $VH_ROOT/logs/$VH_NAME.access_log {
useServer 0
logFormat “%h %l %u %t “%r” %>s %b “%{Referer}i” “%{User-Agent}i””
logHeaders 5
rollingSize 10M
keepDays 10
compressArchive 1
}

scripthandler {
add lsapi:dominio1210 php
}

extprocessor dominio1210 {
type lsapi
address UDS://tmp/lshttpd/dominio1210.sock
maxConns 10
env LSAPI_CHILDREN=10
initTimeout 600
retryTimeout 0
persistConn 1
pcKeepAliveTimeout 1
respBuffer 0
autoStart 1
path /usr/local/lsws/lsphp80/bin/lsphp
extUser compr1210
extGroup compr1210
memSoftLimit 2047M
memHardLimit 2047M
procSoftLimit 400
procHardLimit 500
}

phpIniOverride {

}

module cache {
storagePath /usr/local/lsws/cachedata/$VH_NAME
}

rewrite {
enable 1
autoLoadHtaccess 1
}

context /.well-known/acme-challenge {
location /usr/local/lsws/Example/html/.well-known/acme-challenge
allowBrowse 1

rewrite {

}
addDefaultCharset off

phpIniOverride {

}
}

vhssl {
keyFile /etc/letsencrypt/live/dominio.pro/privkey.pem
certFile /etc/letsencrypt/live/dominio.pro/fullchain.pem
certChain 1
sslProtocol 24
enableECDHE 1
renegProtection 1
sslSessionCache 1
enableSpdy 15
enableStapling 1
ocspRespMaxAge 86400
}

context / {
type appserver
startupFile server.js
location /home/dominio.pro/public_html
binPath /root/.asdf/installs/nodejs/16.19.1/bin/node
appType node
maxConns 100

rewrite {

}
addDefaultCharset off
}

Hello @marcelodelta

There is where the issue may be. It should be

binPath                 /usr/bin/node

Can you run the app manually via terminal ? plus is it SSG or SSR

Hi,

It is the version of node we are currently using. We are using specific version
/root/.asdf/installs/nodejs/16.19.1/bin/node

This file is not found on our server.
/usr/bin/node

When running the command below directly in the terminal, the app runs without errors.

/root/.asdf/installs/nodejs/16.19.1/bin/node server.js

[01:24:03.176] INFO (delta/1028213): started server on 0.0.0.0:3334

Our app is a PWA

Thank you for your attention.

So you are using expressjs to serve it ?

Our application is made with AdonisJS

Easy. If you have dotenv to specify the port change it to 3333 or 3001

Do you have the build files here or there in /build in same location ?

Does it only work with these ports?

The file for the startup is in the public_html root. server.js

No am just giving you examples. Sometime port 3000 never works use another port is same range

What is your npm version? Anything above 8 should work perfectly

Use PM2 to see why the app doesnt run. Install it and add your app. Its best if your reboot you server after then open monitoring interface to see error logs

Remember the dotenv is not usually copied during build you have to create one inside build folder and copy your database variables and any other environment variables

what would the context look like to use pm2?

PM2 does not serve your app its just a prcoess manager think of it like a “logger” but its just more than that with built in load balancer

Install it globally and save/start your app

$ cd /home/myadonisjsapp.com/public_html
$ npm install pm2 -g
# add app to pm2
$ pm2 start server.js --name "mypwa" --watch
# daemonize your app
$ pm2 startup && pm2 save
# to see all your node apps
$ pm2 list
# Display all apps logs in realtime
$ pm2 monit

we managed to make it work with proxy and using pm2.

Is it better option?

Yes. What errors did you see ?

Does not work

#context / {
#type appserver
#location /home/comprarevender.pro/public_html
#binPath /root/.asdf/installs/nodejs/16.19.1/bin/node
#appType node
#startupFile server.js
#maxConns 100

#rewrite {

}

addDefaultCharset off

#}

It’s work

context / {
type proxy
handler compr1210
addDefaultCharset off
}

rewrite {
RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
RewriteRule /(.*) ws://127.0.0.1:3334/$1 [P]
enable 1
autoLoadHtaccess 1
}

scripthandler {
add proxy:compr1210 php
}

extprocessor compr1210 {
type proxy
address 127.0.0.1:3334
maxConns 100
initTimeout 600
retryTimeout 0
respBuffer 0
}

What is this for ?

If it worked here then there must be something new you introduced to the config. Check that first before saying it doesnt work