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

在CyberPanel(Ubuntu 22.04)环境下将Express服务器部署到srv.example.com域名的配置求助

在CyberPanel(Ubuntu 22.04)环境下将Express服务器部署到srv.example.com域名的配置求助

嘿,我现在碰到个部署难题,想请各位大佬帮忙看看。我用的是Ubuntu 22.04搭配CyberPanel,已经创建了srv.example.com这个站点,而且在它的public_html目录里装了一个Express服务器,我的app.js代码如下:

const express = require('express');
const fs = require('fs');
const https = require('https');
const app = express();
const port = 3001;

const options = {
  key: fs.readFileSync('/etc/letsencrypt/live/srv.example.com/privkey.pem'),
  cert: fs.readFileSync('/etc/letsencrypt/live/srv.example.com/fullchain.pem')
};

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

https.createServer(options, app).listen(port, () => {
  console.log(`Express server is running on https://localhost:${port}`);
});

另外我在Vhosts配置文件里添加了这段代码(不过后面没写完):

<VirtualHost *:443>
ServerName srv.example.com
DocumentRoot /home/srv.example.com/public_html

SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/srv.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/srv.example.com/privkey.pem

Pro...

现在的问题是没办法通过srv.example.com这个域名正常访问我的Express服务,想请教下大家我哪里配置错了?或者有没有遗漏的关键步骤?

这里也整理几个我自己想到的排查方向,供大家参考:

  • 我的Express服务自己起了HTTPS监听3001端口,但CyberPanel的Web服务器(Apache/Nginx)已经在处理443端口的请求,会不会是端口冲突了?是不是应该让Web服务器反向代理到Express的3001端口,而不是让Express自己处理HTTPS?
  • Vhosts里的配置是不是没写完?我贴的代码里的“Pro...”应该是Proxy相关的规则吧?比如是不是需要添加类似这样的反向代理配置:
    ProxyPass / http://localhost:3001/
    ProxyPassReverse / http://localhost:3001/
    
  • 有没有可能是证书路径的权限问题?Express进程有没有权限读取Let's Encrypt的证书文件?
  • 防火墙有没有开放3001端口?不过如果用反向代理的话,是不是其实不需要开放这个端口给外部,只要本地能访问就行?

备注:内容来源于stack exchange,提问作者Christos.S

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.16 12:39:36