我的 https 服务器正在运行,但它不处理请求:
const crypto = require('crypto'),
fs = require("fs"),
http = require("http");
var https = require('https');
var privateKey = fs.readFileSync('C:\\dev\\apps\\OpenSSL-Win64\\batar\\azerty.pem');
var cert = fs.readFileSync('C:\\dev\\apps\\OpenSSL-Win64\\batar\\tg.pem');
var options = {
key: privateKey,
cert: cert
};
console.log( options );
https.createServer(options, function (req, res) {
console.log("handling request");
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
当我输入服务器地址 localhost:8000 时,浏览器会加载很长时间,最终会出现“空响应”错误。
这是服务器输出:
C:\>node dev\nouille\server.js
{ key: <Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 52 53 41 20 50 52 49 56 41 54 45 20 4b 45 59 2d 2d 2d 2d 2d 0a 4d 49 49 43 58 51 4
9 42 41 41 4b 42 67 51 44 56 61 4c 41 ...>,
cert: <Buffer 2d 2d 2d 2d 2d 42 45 47 49 4e 20 43 45 52 54 49 46 49 43 41 54 45 2d 2d 2d 2d 2d 0a 4d 49 49 43 66 7a 43 43 41 65
67 43 43 51 43 63 66 52 6a 78 57 32 72 ...> }