gpt4 book ai didi

node.js - 在 Node Express 应用程序中安装 Entrust SSL 证书

转载 作者:太空宇宙 更新时间:2023-11-03 13:25:28 25 4
gpt4 key购买 nike

我不确定如何传递给定的证书来启动 https 服务器。 Entrust 提供了以下文件:
1. 根证书。 (.txt)
2.链根证书文件。 (.txt)
3.链证。 (.txt)
4. 服务器证书。 (.crt)

我的 Express 应用目前需要:

exports.key1 = {
key:'./server/config/keys/server.key', // ?
cert:'./server/config/keys/server.crt', // ?
ca:'./server/config/keys/ca.csr' //given to entrust to generate their cert
};

我不确定如何修改 key 以匹配新文件。

最佳答案

连接证书后,颁发者会提供相关说明,您需要从文件系统中读取它们并将它们提供给 http.createServer()创建 SSL 服务器对象。来自文档:

var https = require('https');
var fs = require('fs');

var options = {
key: fs.readFileSync('path/to/agent-key.pem'),
cert: fs.readFileSync('path/to/agent-cert.pem')
};

https.createServer(options, function (req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);

通常,您会将选项 block 包裹在一个标志中,以检查您是在生产还是开发中。对于生产,您将从安全的预定义路径读取证书,而对于开发,您可以生成这些证书并在根项目文件夹 fixtures/ 中提供它们,您也可以将其与项目存储库,如果它更方便。使用以下内容创建用于开发的自颁发证书:

openssl req -batch \
-new -x509 -sha256 -newkey rsa:2048 -nodes -days 365 \
-keyout fixtures/dev.key \
-out fixtures/dev.crt;

关于node.js - 在 Node Express 应用程序中安装 Entrust SSL 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33223899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com