Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在nodejs express中运行https服务器时出错\u SSL\u协议\u错误浏览器错误消息_Node.js_Https_Express - Fatal编程技术网

Node.js 在nodejs express中运行https服务器时出错\u SSL\u协议\u错误浏览器错误消息

Node.js 在nodejs express中运行https服务器时出错\u SSL\u协议\u错误浏览器错误消息,node.js,https,express,Node.js,Https,Express,我有许多nodejs应用程序使用下面的代码在Express上运行。使用类似以下代码,它们都可以正常运行: fs = require 'fs' https = require 'https' express = require 'express'

我有许多nodejs应用程序使用下面的代码在Express上运行。使用类似以下代码,它们都可以正常运行:

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}"  

但是,当尝试使用此代码创建新应用程序时,我在启动https服务器时看到ERR_SSL_PROTOCOL_错误。知道是什么导致了这个问题吗?

我发现这是从express 2.5.8迁移到express 3时引起的,特别是3.0.0beta4。创建新项目时,从npm中提取的版本已更改为版本3系列。即使在运行
express--version
时模块被标记为“beta”,但在运行
npm install express
时,此版本就是现在安装的版本。这些变化的细节将被概述

为了解决这个问题,我使用了以下代码:

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

你能理解有什么不同吗?添加的ca?这有什么帮助?