node.js app stalls in vhost context — CyberPanel - WebHosting Control Panel for OpenLiteSpeed
CyberLoader

node.js app stalls in vhost context

having some trouble proxying a node application via vhosts and would greatly appreciate any help:

my app works fine if i run node /usr/local/lsws/fcgi-bin/lsnode.js from the bash prompt, whether as root or the owner of the app. i can curl it just fine. but if i have it setup as a vhost context config, it just hangs—timeout error.

vhost conf:

context /api {
type appserver
location /home/mysite.com/app
binPath /bin/node
appType node
maxConns 100

rewrite {
}

addDefaultCharset off
}


error:

Request Timeout
This request takes too long to process, it is timed out by the server. If it should not be timed out, please contact administrator of this web site to increase 'Connection Timeout'.

and the error log:

2020-04-07 03:37:27.849954 [NOTICE] [LocalWorker::workerExec] VHost:mysite.com suExec check uid 99 gid 99 setuidmode 0.
2020-04-07 03:37:27.849984 [NOTICE] [LocalWorker::workerExec] Config[Node:mysite.com:/api]: suExec uid 99 gid 99 cmd /bin/node /usr/local/lsws/fcgi-bin/lsnode.js, final uid 99 gid 99.
2020-04-07 03:37:27.851083 [NOTICE] [Node:mysite.com:/api] add child process pid: 66195.
GET /api/add HTTP/1.1
Host: mysite.com
Connection: keep-alive
DNT: 1
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.162 Safari/537.36 Edg/80.0.361.109
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip
Accept-Language: en-US,en;q=0.9
Cookie: __cfduid=d0eaf6bdad767429fcbd638800e26ad131586216468
X-Forwarded-Host: mysite.com
X-Forwarded-For: XX.XX.XX.XX

2020-04-07 03:37:29.066219 [INFO] Process with PID: 66195 is dead
2020-04-07 03:42:28.726306 [INFO] [XX.XX.XX.XX:33308#mysite.com] Connection idle time too long: 301 while in state: 6 watching for event: 0, close!
2020-04-07 03:42:28.726355 [INFO] [XX.XX.XX.XX:33308] Content len: 0, Request line:
GET /api/add HTTP/1.1
2020-04-07 03:42:28.726362 [INFO] [XX.XX.XX.XX:33308#mysite.com] HttpExtConnector state: 8, request body sent: 0, response body size: -2, response body sent:0, left in buffer: 0, attempts: 0.
2020-04-07 03:42:28.726369 [INFO] [XX.XX.XX.XX:33308#mysite.com] Proxy connection state: 2, watching event: 25, Request header:599, body:0, sent:0, Response header: 0, total: 0 bytes received in 301 seconds,Total processing time: 301.
2020-04-07 03:47:29.066920 [NOTICE] [Node:mysite.com:/api] stop worker processes

Comments

  • @selfagency I know your post was pretty long ago, but could you solve your issue? I have the same problem now and I don't know why. I am trying to host my node/nestjs application but only get timeouts.
  • https://forums.cyberpanel.net/discussion/320/tutorial-how-to-use-openlitespeed-as-reverse-proxy-server

    This can help to set up reverse proxy.
  • edited May 25
    Hi @usmannasir,
    thank you for posting the link. I followed all the instructions but still, I can't get it running.

    This is my vHost:

    extprocessor staging {
    type proxy
    address 127.0.0.1:2053
    maxConns 100
    env NODE_ENV=production
    initTimeout 60
    retryTimeout 60
    respBuffer 0
    }

    context / {
    type appserver
    location /home/staging.example.com/public_html/dist/apps/exampleapp
    binPath /usr/bin/node
    appType node
    startupFile main.js
    maxConns 100

    rewrite {

    }
    addDefaultCharset off
    }


    My Rewrite rules:

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    RewriteRule ^(.*)$ http://postgres/$1 [P] #postgres docker container
    RewriteRule ^/(.*)$ http://staging/$1 [P,E=Proxy-staging.example.com]


    When I run the node command "node dist/apps/exampleapp/main" via ssh it works:
    [NestApplication] Nest application successfully started +22ms

    but I still get a timeout when I open https://staging.example.com in my browser.


    Thank you for your help in advance!
  • edited May 25
    UPDATE:

    I forgot to mention that http://[IP-ADDRESS]:[PORT] is working perfectly
    and I fixed one typo:
    RewriteRule ^/(.*)$ http://staging/$1 [P,E=Proxy-staging.example.com]
    to
    RewriteRule ^/(.*)$ http://staging/$1 [P,E=Proxy-Host:staging.example.com]

    but still not working :-(
  • No one with ideas what I could try?
  • Now I am facing the same problem for the Next JS application in ubuntu (cyberpanel). But in cent os + cyberpanel working fine
Sign In or Register to comment.
CyberPanel Discord

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!