我在 GoDaddy 购买了 SSL 证书,并使用以下 node.js 服务器尝试设置它:
var https = require('https'), // module for https
fs = require('fs'); // required to read certs and keys
var options = {
key: fs.readFileSync('../../ssl/example.com.key'),
cert: fs.readFileSync('../../ssl/example.com.crt'),
ca: fs.readFileSync('../../ssl/gd_bundle.crt'),
requestCert: true,
rejectUnauthorized: false
};
https.createServer(options, function (req, res) {
if (req.client.authorized) {
res.writeHead(200, {"Content-Type": "application/json"});
res.end('{"status":"approved"}');
} else {
res.writeHead(401, {"Content-Type": "application/json"});
res.end('{"status":"denied"}');
}
}).listen(443);
运行服务器后,我尝试访问https://example.com的网站,我得到了
{"status":"denied"}
我想这是正常工作,因为我得到了回应,但我认为我对 SSL 工作原理的理解是错误的。我认为浏览器从服务器获取证书,然后根据根证书(即来自 GoDaddy)对其进行身份验证。所以我不应该得到
{"status":"approved"}
只是简单地访问https://example.com?
所以我想我的问题是,我如何访问https://example.com并获得 {"status":"approved"}?
谢谢!