使用最新的Node和NPM,Express服务器中的SSL握手失败

10

我在我的 Mac 上将 Node.js 升级到最新版本 0.12.4,同时将 NPM 升级到2.10.1,然后重新运行 Express 项目的 npm install 命令。

现在,在 Chrome 中访问 https://localhost:3001 时,会显示“该网页不可用/ ERR_CONNECTION_REFUSED”错误。当我运行 curl -v https://localhost:3001 命令时,输出结果为:

curl -v https://localhost:3001/
* Hostname was NOT found in DNS cache
*   Trying ::1...
* Connected to localhost (::1) port 3001 (#0)
* Server aborted the SSL handshake
* Closing connection 0
curl: (35) Server aborted the SSL handshake
这肯定是由于升级 Node.js 导致的结果,因为问题在升级后立即出现。
我是这样启动服务的:
options = {
    key: fs.readFileSync('sslkey.pem'),
    cert: fs.readFileSync('sslcert.pem')
};
http.createServer(app).listen(settings.apiPort);
https.createServer(options, app).listen(settings.apiSSLPort);
console.log('Listening on ports: ' + settings.apiPort + ' and ' + settings.apiSSLPort);

有人有任何想法是什么原因导致这个问题吗?


尝试使用不同的浏览器并清除缓存。 - deek
curl -k -v https://localhost:3001/ 显示了什么? -k 选项告诉 curl 忽略安全警告,继续连接。这个选项和 -v 一起使用,可以提供更多关于服务器证书的信息。或者,您也可以使用 openssl s_client -connect localhost:3001 命令。有趣的部分是确定在 SSL 握手期间何时关闭连接。 - Castaglia
1个回答

2

我有同样的问题,尝试以下方法:

options = {
        key: fs.readFileSync('sslkey.pem', 'utf-8'),
        cert: fs.readFileSync('sslcert.pem', 'utf-8'),
        ca: fs.readFileSync(<CA_FILE>, 'utf-8'),
        requestCert: true,
        rejectUnauthorized: false
    };

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接