简体   繁体   English

NodeJS https服务器使用express返回ERR_SSL_PROTOCOL_ERROR

[英]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.

相关问题 POST https://localhost:5000/stored net::ERR_SSL_PROTOCOL_ERROR - POST https://localhost:5000/stored net::ERR_SSL_PROTOCOL_ERROR 连接建立错误:尝试建立并连接到Websocket服务器时,抛出net :: ERR_SSL_PROTOCOL_ERROR - Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR is thrown when trying establish and connect to a websocket server socket.io 错误网络::ERR_SSL_PROTOCOL_ERROR - socket.io error net::ERR_SSL_PROTOCOL_ERROR 无法连接到安全 socket.io 服务器:ERR_SSL_PROTOCOL_ERROR - Cannot connect to secure socket.io server : ERR_SSL_PROTOCOL_ERROR 跨域请求的间歇性 ERR_SSL_PROTOCOL_ERROR 错误 - Intermittent ERR_SSL_PROTOCOL_ERROR error for cross domain request PHP Websocket 错误:net::ERR_SSL_PROTOCOL_ERROR 使用 cloudflare - PHP Websocket ERROR: net::ERR_SSL_PROTOCOL_ERROR using cloudflare 在 react js 中使用新闻 api 时加载资源失败:net::ERR_SSL_PROTOCOL_ERROR - Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR while using news api in react js 如何处理net :: ERR_SSL_PROTOCOL_ERROR? - How to deal with net::ERR_SSL_PROTOCOL_ERROR? Wordpress - 错误 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL 协议错误 - Wordpress - Error 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error 具有SSL的Azure辅助角色上的Node.js导致ERR_SSL_PROTOCOL_ERROR - Node.js on Azure Worker Role w/ SSL results in ERR_SSL_PROTOCOL_ERROR
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM