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

Unleash HTTPS配置及多端口运行问题咨询

Unleash服务端配置解决方案

原代码

const unleash = require('unleash-server');
unleash
.start({
db: {
ssl: false,
host: 'localhost',
port: 5432,
database: 'unleash',
user: 'unleash_user',
password: 'password',
},
server: {
port: 8443,
},
})
.then((unleash) => {
console.log(
`Unleash started on http://localhost:${unleash.app.get('port')}`,
);
});

问题1:为8443端口配置HTTPS证书

要启用HTTPS,需在server配置项中添加https对象,通过fs模块读取本地证书和密钥文件内容传入。修改后的代码如下:

const unleash = require('unleash-server');
const fs = require('fs');

unleash
.start({
  db: {
    ssl: false,
    host: 'localhost',
    port: 5432,
    database: 'unleash',
    user: 'unleash_user',
    password: 'password',
  },
  server: {
    port: 8443,
    https: {
      key: fs.readFileSync('/vault/secrets/key.pem'),
      cert: fs.readFileSync('/vault/secrets/cert.pem'),
    },
  },
})
.then((unleash) => {
  console.log(
    `Unleash HTTPS服务启动成功:https://localhost:${unleash.app.get('port')}`,
  );
});

说明:

  • 引入fs模块读取本地证书文件,需确保Unleash进程有权限访问/vault/secrets/路径下的文件
  • 配置server.https项传入密钥和证书内容后,Unleash会自动以HTTPS模式监听8443端口

问题2:同时运行HTTP 4242端口和HTTPS 8443端口

Unleash默认只启动一个服务,但可以利用其返回的Express应用实例,手动创建HTTP服务器监听4242端口,同时保留HTTPS服务。修改后的代码如下:

const unleash = require('unleash-server');
const fs = require('fs');
const http = require('http');

unleash
.start({
  db: {
    ssl: false,
    host: 'localhost',
    port: 5432,
    database: 'unleash',
    user: 'unleash_user',
    password: 'password',
  },
  server: {
    port: 8443,
    https: {
      key: fs.readFileSync('/vault/secrets/key.pem'),
      cert: fs.readFileSync('/vault/secrets/cert.pem'),
    },
  },
})
.then((unleash) => {
  // 启动HTTP服务器监听4242端口
  http.createServer(unleash.app).listen(4242, () => {
    console.log('Unleash HTTP服务启动成功:http://localhost:4242');
  });
  console.log(
    `Unleash HTTPS服务启动成功:https://localhost:${unleash.app.get('port')}`,
  );
});

说明:

  • Unleash启动后返回的unleash.app是Express应用实例,可直接挂载到自定义的HTTP服务器上
  • 用Node.js内置的http模块创建新服务器,监听4242端口,实现HTTP和HTTPS服务同时运行

内容的提问来源于stack exchange,提问作者Deepak Grover

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 20:13:11