[英]ssl version or cipher mismatch ExpressJS
I have a problem with https in express and I don't really understand it:我在 express 中使用 https 有问题,我不太明白:
This is from my last project (it works):这是我上一个项目(它有效):
index.js:索引.js:
var fs = require('fs');
var http = require('http');
var https = require('https');
var privateKey = fs.readFileSync(__dirname + '/cert/server.key', 'utf8');
var certificate = fs.readFileSync(__dirname + '/cert/server.cert', 'utf8');
var credentials = {key: privateKey, cert: certificate};
var express = require('express');
var app = express();
var httpServer = http.createServer(app);
var httpsServer = https.createServer(credentials, app);
httpServer.listen(80);
httpsServer.listen(443);
//Force https
app.use(function(req, res, next) {
if(!req.secure) {
return res.redirect(['https://', req.get('Host'), req.url].join(''));
}
next();
});
This is from my current project (doesn't work):这是来自我当前的项目(不起作用):
index.js:索引.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);
web_server.js: web_server.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();
});
I am using the same certificate and key as before and never got an fs-error while reading a file or something.我使用与以前相同的证书和密钥,并且在读取文件或其他内容时从未出现 fs 错误。
But when I go to localhost via the browser I get this message: ERR_SSL_VERSION_OR_CIPHER_MISMATCH .但是当我通过浏览器访问 localhost 时,我收到以下消息: ERR_SSL_VERSION_OR_CIPHER_MISMATCH 。
Please keep in mind that I am fairly new to Node.js - thank you very much in advance!请记住,我是 Node.js 的新手 - 非常感谢您! ;)
;)
Looks like you've got a typo:看起来你有一个错字:
var credential = { key: privateKey, vert: certificate };
"vert" instead of "cert" :) “vert”而不是“cert” :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.