我是Node.js的新手,我的问题对某些人来说可能很愚蠢,请原谅我。
在过去,我在EC2实例上安装了Apache。我在这个目录/var/www/html/ping.html.中创建了ping.html
健康检查为:Ping端口:80,Ping Path:/ping.html。
我不知道如何为Node.js做同样的事情。我应该在哪里创建这个ping.html文件,因为Node.js没有这样的目录或者我该怎么做才能通过Node.js的电子健康检查?
我读了很多说明,但似乎对我来说太“太多”了。
发布于 2016-03-23 20:34:31
这取决于您要检查什么,以及您在node.js中使用的是什么。如果您只想让检查确保node.js服务器正在运行,那么只需将其添加到HTTP:
var server = http.createServer(function(request, response) {
if (request.url === '/ping.html' && request.method ==='GET') {
//AWS ELB pings this URL to make sure the instance is running
//smoothly
response.writeHead(200, {
'Content-Type': 'text/plain',
'Content-Length': 2
});
response.write('OK');
response.end();
}
//Do the rest of your web server here
});
server.listen(8080 /* Whatever port */);
如果您使用的是像express.js这样的服务器内容的节点,那么可以让ELB检查express.js服务的页面的内容。
https://stackoverflow.com/questions/36188048
复制相似问题