NodeJS https服务器使用express返回ERR_SSL_PROTOCOL_ERROR [英] NodeJS https server returning ERR_SSL_PROTOCOL_ERROR using express
本文介绍了NodeJS https服务器使用express返回ERR_SSL_PROTOCOL_ERROR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在我的nodejs服务器上运行SSL https,但浏览器返回ERR_SSL_PROTOCOL_ERROR
I'm trying to get SSL https working on my nodejs server but the browser returns a ERR_SSL_PROTOCOL_ERROR
代码:
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
如果您使用的是Mac,那将无效相反,你需要这样做才能使密钥长度为2048:
That will not work if you're on a Mac, and instead you need to do this to make the key length 2048:
openssl genrsa -out key.pem 2048
总之,请按照以下步骤在Mac上制作正确的密钥:
In summary, do these steps to make a correct key on 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
这篇关于NodeJS https服务器使用express返回ERR_SSL_PROTOCOL_ERROR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文