我希望设置超时,但只能使用HTTP服务器。
我的代码:
if (options.web_server_encryption === true) {
if (options.dev == 0) {
var httpserver = http.createServer(greenlock.middleware(function (req, res) {
try {
res.writeHead(301, {"Location": "https://" + req.headers['host'] + req.url})
} catch (e) {
console.log(e)
}
res.end()
})).listen(options.http_port, function () {
logger.info(stringbuilder.ldmb("httpstart", options));
});
httpserver.timeout = 5000;
optionsdevcsfs = greenlock.httpsOptions;
} else {
var httpserver = http.createServer(function (req, res) {
try {
res.writeHead(301, {"Location": "https://" + req.headers['host'] + req.url})
} catch (e) {
console.log(e)
}
res.end()
}).listen(options.http_port, function () {
logger.info(stringbuilder.ldmb("httpstart", options));
});
httpserver.timeout = 5000;
optionsdevcsfs = {key: options.key, cert: options.cert};
}
var httpsserver = https.createServer(optionsdevcsfs, app).listen(options.https_port, function () {
logger.info(stringbuilder.ldmb("httpsstart", options));
});
httpsserver.timeout = 5000;
} else if (options.web_server_encryption === false) {
app.listen(options.http_port, function () {
logger.info(stringbuilder.ldmb("httpstart", options));
});
} else {
logger.error(stringbuilder.ldmb("httpnotstart"));
}
if (options.wse_server_encryption === true) {
var server = https.createServer(optionsdevcsfs, wse).listen(options.wse_port, function () {
logger.info(stringbuilder.ldmb("wssstart", options)); //wss
wseinit();
});
server.timeout = 5000;
} else if (options.wse_server_encryption === false) {
var server = http.createServer(wse).listen(options.wse_port, function () {
logger.info(stringbuilder.ldmb("wssstart", options)); //ws
wseinit();
});
server.timeout = 5000;
} else {
logger.error(stringbuilder.ldmb("wssnotstart"));
}
我用命令测试它:
time nc test.trackhe.de 443
我在端口80上有5秒钟,在另一个端口上有2分钟超时 - 我猜是默认值。我尝试使用 env.production 位,它没有效果。