我想在不重新启动的情况下更新node.js http2服务器上的ssl证书(以避免停机)。此外,我不想使用这项工作的任何第三方模块。只有纯nodejs。有可能吗?
现在,当证书即将到期时,我只是重新启动脚本。
const https = require('http2');
const server = https.createSecureServer({
ca: fs.readFileSync('chain.pem'),
cert: fs.readFileSync('cert.pem', 'utf8'),//fullchain
key: fs.readFileSync('privkey.pem', 'utf8'),
allowHTTP1: true,
},我希望能够观察证书文件是否更新(例如,使用fs.watch() ),并动态更新http2服务器中的证书……
发布于 2019-07-25 16:35:47
正如杰克提到的,setSecureContext()实现了魔术。似乎可以在不中断当前连接的情况下更新证书。类似于:
setTimeout(function () {server.setSecureContext({
ca: fs.readFileSync('chain.pem'),
cert: fs.readFileSync('cert.pem', 'utf8'),//fullchain
key: fs.readFileSync('privkey.pem', 'utf8')
})},86400000)发布于 2019-07-24 05:09:27
可以,您可以只使用sniCallBack()
const https = require('http2');
const server = https.createSecureServer({
ca: fs.readFileSync('chain.pem'),
cert: fs.readFileSync('cert.pem', 'utf8'),//fullchain
key: fs.readFileSync('privkey.pem', 'utf8'),
allowHTTP1: true,
SNICallback: (servername, cb) => {
// here you can even change up the `SecureContext`
// based on `servername` if you want
cb(null, server);
}
},这可能有点过时了,所以尝试一下,然后问我是否有什么不起作用,因为我发现here的解决方案源代码有点不同。
https://stackoverflow.com/questions/57169409
复制相似问题