You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CyberPanel OpenLiteSpeed部署Node.js(TypeScript)站点遇超时问题求助

部署Node.js(TypeScript)应用到CyberPanel时请求超时问题排查

问题详情

已在VPS上安装CyberPanel,部署Node.js(TypeScript)应用时,通过以下npm命令完成构建:

"build": "tsc --project ./&&copyFiles www/* build",
"build-deploy": "npm run build && cp package*.json build && cd build && npm install --only=production",

构建产物已上传至public_html目录,但访问站点时触发超时错误:

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

当前vHost配置如下:

docRoot                   $VH_ROOT/public_html
vhDomain                  $VH_NAME
vhAliases                 www.$VH_NAME
adminEmails               xxxxxx@gmail.com
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:apidi5248 php
}

extprocessor apidi5248 {
  type                    lsapi
  address                 UDS://tmp/lshttpd/apidi5248.sock
  maxConns                10
  env                     LSAPI_CHILDREN=10
  initTimeout             600
  retryTimeout            0
  persistConn             1
  pcKeepAliveTimeout      1
  respBuffer              0
  autoStart               1
  path                    /usr/local/lsws/lsphp81/bin/lsphp
  extUser                 apidi5248
  extGroup                apidi5248
  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/api.digilifesoftware.com/privkey.pem
  certFile                /etc/letsencrypt/live/api.digilifesoftware.com/fullchain.pem
  certChain               1
  sslProtocol             24
  enableECDHE             1
  renegProtection         1
  sslSessionCache         1
  enableSpdy              15
  enableStapling           1
  ocspRespMaxAge           86400
}

context / {
  type                    appserver
  location               $VH_ROOT/public_html
  startupFile             server.js
  binPath                 /usr/bin/node
  appType                 node
  maxConns                100
 
  accessControl  {
    allow                 *
  }

  rewrite  {

  }
  addDefaultCharset       off
}

排查与修复步骤

1. 手动验证Node应用能否正常启动

登录VPS,进入public_html目录,执行node server.js,观察控制台输出:

  • 若有报错(如依赖缺失、语法错误),根据提示修复问题
  • 若无报错,用curl http://localhost:3000(替换为应用实际监听端口)测试是否能正常响应
  • 确认应用监听地址为0.0.0.0而非localhost,否则LSWS无法建立连接

2. 完善vHost的Node应用Context配置

当前context /块缺少关键超时和启动参数,补充以下配置:

context / {
  type                    appserver
  location               $VH_ROOT/public_html
  startupFile             server.js
  binPath                 /usr/bin/node
  appType                 node
  maxConns                100
  # 新增超时与启动参数
  initTimeout             60
  connTimeout             30
  retryTimeout            0
  persistConn             1
  respBuffer              0
  autoStart               1
  env                     NODE_ENV=production
  # 若应用监听自定义端口,添加以下行(替换为实际端口)
  # port                    3000
 
  accessControl  {
    allow                 *
  }

  rewrite  {

  }
  addDefaultCharset       off
}

修改后重启LSWS服务:systemctl restart lsws

3. 检查文件权限

确保public_html目录及所有文件的所有者为站点对应的系统用户(如apidi5248),权限设置:

  • 目录:chmod 755 public_html
  • 文件:chmod 644 public_html/*
  • 递归设置:chown -R apidi5248:apidi5248 public_html

4. 查看日志定位细节

查看站点错误日志:tail -f $VH_ROOT/logs/$VH_NAME.error_log,或LSWS全局日志:tail -f /usr/local/lsws/logs/error.log,查找以下关键信息:

  • Node应用启动失败的具体原因
  • LSWS与Node应用连接失败的报错

5. 验证Node版本兼容性

对比本地开发环境与VPS上的Node版本:

  • VPS执行:node -v
  • 若版本差异较大,升级或降级VPS上的Node版本,确保与开发环境一致

内容的提问来源于stack exchange,提问作者Alvin Stefanus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 00:40:23