简体   繁体   中英

ERR_SSL_PROTOCOL_ERROR browser error message while running a https server in nodejs express

I have a number of nodejs applications running on Express using the code below. They all run fine using code similar to the following:

fs = require 'fs'                                                               
https = require 'https'                                                         
express = require 'express'                                                     
server_port = 3000                                                              
keys_dir = 'keys/'                                                              server_options = {
  key  : fs.readFileSync(keys_dir + 'privatekey.pem'), 
  cert : fs.readFileSync(keys_dir + 'certificate.pem')                          }                                                                                             app = express.createServer(server_options)
app.listen server_port 
console.log "HTTPS Server started on port #{server_port}"  

However, when trying to create a new application using this code I see a ERR_SSL_PROTOCOL_ERROR when starting the https server. Any idea what is causing this problem?

I discovered that was caused when moving from express 2.5.8 to express 3 - specifically 3.0.0beta4. When creating a new project the version pulled from npm had changed to the version 3 series. Even though the module is marked as "beta" when you run express --version this version is what is installed now when running npm install express . The details of the changes are outlined here .

To solve this for my case I used the following code:

const fs = require("fs");
const https = require("https");
const express = require("express");

const keysDir = "keys/";
const options = {
  key  : fs.readFileSync(keysDir + "privatekey.pem"),
  ca   : fs.readFileSync(keysDir + "certrequest.csr"),
  cert : fs.readFileSync(keysDir + "certificate.pem")
};

const app = express();
https.createServer(options, app).listen(3000);

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