我见过其他类似的问题,但没有解决我的问题。我已经生成了我的TLS (openSSL)自签名证书,但似乎不在我的NodeJS服务器上工作。
指令以生成SSL
openssl req -newkey rsa:2048 -keyout key.pem -x509 -days 365 -out certificate.pem
openssl x509 -text -noout -in certificate.pem
openssl pkcs12 -inkey key.pem -in certificate.pem -export -out certificate.p12
openssl pkcs12 -in certificate.p12 -noout -info // verify certificate因此,在最后,我有.p12,也称为PFX类型证书。下面是我的Node.js代码:
// ------- Start HTTPS configuration ----------------
const options = {
pfs: fs.readFileSync('./server/security-certificate/certificate.p12'),
passphrase: 'secrete2'
};
https.createServer(options, app).listen(8443);
// -------- End HTTPS configuration -----------------
// Also listen for HTTP
var port = 8000;
app.listen(port, function(){
console.log('running at localhost: '+port);
});以下是我运行curl命令时的输出,HTTP请求得到了正确的处理,只有HTTPS有问题:

此外,如果我这样做:
export CURL_CA_BUNDLE=/var/www/html/node_app/server/security-certificate/cert.p12然后我得到以下错误:curl: (77) Problem with the SSL CA cert (path? access rights?)
如果我尝试使用HTTPS和端口在浏览器中访问,浏览器说它无法加载页面。
我遵循的参考链接: Node.js HTTPS: requestlistener 我在使用AWS RedHat Linux
发布于 2018-05-10 08:35:20
到目前为止,还不知道与我的.p12包证书(在我的Node.js配置中使用)有关的上述问题的解决方案。
但是,我注意到,当我更改代码并尝试使用.pem证书时,它与curl -k <MY-URL>命令一起正确工作。
const options = {
cert: fs.readFileSync('./server/security-certificate/cert.pem'),
key: fs.readFileSync('./server/security-certificate/key.pem'),
//pfs: fs.readFileSync('./server/security-certificate/cert.p12'), // didn't work
passphrase: 'secrete'
};
https.createServer(options, app).listen(8443);如果有人知道更好的解决方案/回答,请张贴。到目前为止,我不知道为什么.p12证书不能工作。我应该把它重命名为.pfx (有什么不同和效果)?
https://stackoverflow.com/questions/50194109
复制相似问题