NodeJS https server returning ERR_SSL_PROTOCOL_ERROR using express

14,280

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
Share:
14,280
Callum
Author by

Callum

Updated on August 02, 2022

Comments

  • Callum
    Callum over 1 year

    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);