[英]NodeJS https server returning ERR_SSL_PROTOCOL_ERROR using express
I'm trying to get SSL https working on my nodejs server but the browser returns a ERR_SSL_PROTOCOL_ERROR我试图让 SSL https 在我的 nodejs 服务器上工作,但浏览器返回 ERR_SSL_PROTOCOL_ERROR
code:代码:
var express = require('express');
var https = require('https');
var http = require('http');
var fs = require('fs');
var options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
}
http.createServer(app).listen(80);
https.createServer(options, app).listen(443);
This will happen if your key isn't generated correctly.如果您的密钥未正确生成,则会发生这种情况。
A lot of places will tell you to do this:很多地方会告诉你这样做:
openssl genrsa -out key.pem
That will not work if you're on a Mac, and instead you need to do this to make the key length 2048:如果您使用的是 Mac,这将不起作用,您需要这样做以使密钥长度为 2048:
openssl genrsa -out key.pem 2048
In summary, do these steps to make a correct key on Mac:总之,请执行以下步骤以在 Mac 上制作正确的密钥:
openssl genrsa -out key.pem 2048
openssl req -new -key key.pem -out client.csr
openssl x509 -req -in client.csr -signkey key.pem -out cert.pem
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.