Node.js HTTPS配置错误 - 没有常见的加密算法 [英] Node.js HTTPS configuration error - no common encryption algorithm(s)
问题描述
我看过其他类似的问题,但没有解决我的问题。我已经生成了我的TLS(openSSL)自签名证书,但似乎无法在我的 NodeJS
服务器上运行。
I have seen other similar questions but non addresses my problem. I have generated my TLS (openSSL) Self-Signed certificate, but seems not working on my NodeJS
server.
生成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 代码:
So at the end I have .p12
also known as PFX
type certificate. Below is my Node.js code:
// ------- 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有问题:
Here is the output when I run curl
command, the HTTP request is served correctly, only HTTPS has problem:
此外,如果我这样做:
export CURL_CA_BUNDLE=/var/www/html/node_app/server/security-certificate/cert.p12
然后我收到以下错误:
curl:(77)SSL CA证书问题(路径?访问权限?)
Then I get following error:
curl: (77) Problem with the SSL CA cert (path? access rights?)
如果我尝试使用HTTPS和端口在浏览器中访问,浏览器会说它无法加载页面。
If I try to access in browser with HTTPS and port, browser says it could not load the page.
我遵循的参考链接:
Node.js HTTPS:
Reference links I followed: Node.js HTTPS:
我m使用AWS RedHat Linux
I'm using AWS RedHat Linux
推荐答案
到目前为止还不知道上面发布的解决方案与我的 .p12
捆绑证书相关的问题(在我的 Node.js
配置中使用)。
So far don't know the solution to the above posted problem related to my .p12
bundle certificate (used in my Node.js
configuration).
但是我注意到当我更改代码并尝试使用 .pem
证书时,它与 curl -k< MY-URL>
命令。
However I have noticed that when I changed the code and tried to use the .pem
certificate, it worked correctly with curl -k <MY-URL>
command.
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
(有什么不同和效果)?
If any one knows better solution/answer please post that. So far, I'm not sure why .p12
certificate does not work. Should I rename it to .pfx
(what is the different and effect)?
这篇关于Node.js HTTPS配置错误 - 没有常见的加密算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!