我的 Nodejs 网页未使用 Cyberpanel 加载

问题描述 投票:0回答:0

我试过在 SO 上到处寻找,但找不到任何似乎对我有帮助的东西。

我已经用 Ubuntu 22.04 和 Cyberpanel 设置了一个 VPS 作为我的控制面板。我已按照指示将我的 Node.js 1 页网站上传到“public_html”文件夹。

现在只有一页,因为我的目标是用多页等扩展它……

当我在自己的本地服务器 (localhost:3000) 上运行该应用程序时,一切运行顺利。我使用 EJS 作为视图引擎。

我得到的最接近的是下面的设置,当我访问我的域时,页面只会加载和加载,直到出现超时错误。在那之前我只是收到 404 错误。

请注意,我将所有路线保存在一个单独的文件夹中(目前我只有一条路线)。

const app = express();
import path from 'path'
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
import bodyParser from 'body-parser'
import cookieParser from 'cookie-parser'
const port = 3000
import Sequelize from 'sequelize'
import sequelize from "./config/database.js";
import ejs from 'ejs'
import ejsLint from 'ejs-lint'
import expressLayouts from 'express-ejs-layouts'
import mainRoutes from "./routes/mainroute.js";


app.use(express.json())
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, '/public')));
app.use(cookieParser());


// Connect all the routes to  my app
app.use(mainRoutes)


// EJS
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');


// Test connection to database
sequelize
  .authenticate()
  .then(() => {
    console.log('Connected to database successfully.');
  })
  .catch(err => {
    console.error('Unable to connect to the database:', err);
  });

  sequelize.sync()
  .then(() => {
    console.log('Tables created if it does not already exist');
  }).catch(err => {
    console.log('Table has not been created');
  });



app.listen(port, () => {
  console.log(`Connected to server on port ${port}`)
})

我的虚拟主机会议:

vhDomain                  $VH_NAME
vhAliases                 www.$VH_NAME
adminEmails               [email protected]
enableGzip                1
enableIpGeo               1


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:username php
}

extprocessor sicil6626 {
  type                    lsapi
  address                 UDS://tmp/lshttpd/username.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                 username
  extGroup                username
  memSoftLimit            2047M
  memHardLimit            2047M
  procSoftLimit           400
  procHardLimit           500
}

phpIniOverride  {
php_admin_value open_basedir "/tmp:$VH_ROOT"
}

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

rewrite  {
 enable                  1
  autoLoadHtaccess        1
}

context / {
type appserver
location /home/mydomaingoeshere.co.uk/public_html
binPath /usr/bin/node
appType node
startupFile app.js
maxConns 100

rewrite {

}
addDefaultCharset off
}

这是我的文件夹结构:

任何帮助将不胜感激,因为我已经为此奋斗了几周。

非常感谢!

node.js express vps cyber-panel
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.