问题描述
我是Node.js的新手,我的问题可能对某人很愚蠢,请对此谅解.
I'm new to Node.js, my question could be stupid to someone, please forgive me for this.
过去,我在EC2实例上安装了Apache.我在此目录/var/www/html/ping.html 中创建了 ping.html .
In the past, I have Apache installed on an EC2 instance. I created ping.html inside this directory /var/www/html/ping.html.
运行状况检查为: Ping端口:80 , Ping路径:/ping.html .
我不知道如何对Node.js进行与上述相同的操作.因为Node.js没有这样的目录/var/www/html/,我应该在哪里创建此 ping.html 文件?或者我应该怎么做才能通过Node.js的ELB运行状况检查?
I don't know how to do the same thing like above for Node.js. Where should I create this ping.html file, because Node.js has no such directory /var/www/html/? Or what should I do to pass the ELB Health check for Node.js?
我阅读了很多说明,但似乎我觉得太多"了.
I read a lot of instructions, but it seems it is "too much" for me to get it.
推荐答案
这取决于您要检查的内容以及与node.js一起使用的内容.如果您只是想检查一下以确保node.js服务器正在运行,则可以简单地将其添加到HTTP服务器:
It depends on what you want to check and what you are using with node.js. If you just wanted the check to make sure that the node.js server is running, you could simply add this to the HTTP server:
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服务的页面的内容即可.
If you are using something with node that servers content like express.js then you could just make the ELB check the content of a page that express.js serves.
这篇关于如何为Node.js配置AWS Elastic Load Balancer的健康检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!