我无法在HTTPS工作node.js后运行服务器。我的目标是使用自签名证书运行Hapi服务器。
这就是我生成自签名证书的方式:
openssl genrsa -out key.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
rm csr.pem
这就是我在Hapi中启动服务器的方式:
server.connection({
port: 9920,
tls: {
key: fs.readFileSync(path.resolve(__dirname, './cert/key.pem')),
cert: fs.readFileSync(path.resolve(__dirname, './cert/cert.pem')),
rejectUnauthorized: false
},
routes: {
cors: true
}
});
为了验证它不是Hapi唯一的问题,我确认这也不适用于vanilla node.js:
var https = require('https');
var fs = require('fs');
var options = {
key: fs.readFileSync(path.resolve(__dirname, './cert/key.pem')),
cert: fs.readFileSync(path.resolve(__dirname, './cert/cert.pem')),
rejectUnauthorized: false
};
var a = https.createServer(options, function (req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
这两个服务器在curl中抛出相同的错误:
$ curl -kiv https://localhost:9920
* Rebuilt URL to: https://localhost:9920/
* Trying ::1...
* connect to ::1 port 9920 failed: Connection refused
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 9920 (#0)
* Server aborted the SSL handshake
* Closing connection 0
curl: (35) Server aborted the SSL handshake
版本:
发生了什么?
答案 0 :(得分:0)
不是ssl的专家,因为没有使用它,但是如果你检查这个代码,那么选项集与你配置的不同。
https://github.com/hapijs/university/blob/master/lib/config.js#L6