简体   繁体   中英

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

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:

openssl genrsa -out key.pem 2048

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM