ssl版本或密码不匹配ExpressJS

时间:2015-10-01 13:53:45

标签: javascript node.js express https certificate

我在快递中遇到了https的问题,我真的不明白它:

这是我上一个项目(可行):

index.js:

var fs = require('fs');

 var configRaw = fs.readFileSync(__dirname + '/config.json', 'utf8', function(err, data) {
     if(err) {
         return abort('Can not read/ find' + __dirname + '/config.json'); //FIXME
     }
 });

 var config = JSON.parse(configRaw);

 console.log('  - loading webserver script..');
 var webServer = require(__dirname + '/lib/web_server.js');

 webServer.init(config.httpPort, config.httpsPort);

这是我当前的项目(不起作用):

index.js:

var fs = require('fs');
var http = require('http');
var https = require('https');

var privateKey = fs.readFileSync(__dirname + '/../ssl/server.key', 'utf8');
var certificate = fs.readFileSync(__dirname + '/../ssl/server.cert', 'utf8');

var credential = { key: privateKey, vert: certificate };
var express = require('express');
var app = express();

var httpServer = http.createServer(app);
var httpsServer = https.createServer(credential, app);

this.init = function(httpPort, httpsPort){
   httpServer.listen(httpPort);
   httpsServer.listen(httpsPort);
}

app.use(function(req, res, next) {
if(!req.secure) {
    return res.redirect(['https://', req.get('Host'), req.url].join(''));
}
   next();  
});

web_server.js:

{{1}}

我使用与以前相同的证书和密钥,在阅读文件或其他内容时从未出现过fs错误。

但是当我通过浏览器访问localhost时,我收到以下消息: ERR_SSL_VERSION_OR_CIPHER_MISMATCH

请记住,我是Node.js的新手 - 非常感谢您提前! ;)

1 个答案:

答案 0 :(得分:12)

看起来你有一个错字:

var credential = { key: privateKey, vert: certificate };

“vert”而不是“cert”:)