【问题标题】:How to configure AWS Elastic Load Balancer's heath check for Node.js如何为 Node.js 配置 AWS Elastic Load Balancer 运行状况检查
【发布时间】:2016-03-24 05:03:42
【问题描述】:

我是 Node.js 的新手,我的问题可能对某些人来说很愚蠢,请原谅我。

过去,我在 EC2 实例上安装了 Apache。我在这个目录 /var/www/html/ping.html 中创建了 ping.html

健康检查将是:Ping Port:80Ping Path:/ping.html

我不知道如何对 Node.js 执行与上述相同的操作。我应该在哪里创建这个 ping.html 文件,因为 Node.js 没有这样的目录 /var/www/html/?或者我应该怎么做才能通过 Node.js 的 ELB 健康检查?

我阅读了很多说明,但对我来说似乎“太多”了。

【问题讨论】:

    标签: javascript node.js amazon-web-services


    【解决方案1】:

    这取决于您要检查的内容以及您在 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 所服务的页面的内容。

    【讨论】:

    • 非常感谢!有用。我只想让 ELB 通过健康检查。
    • 嗨@GnodNart你能帮我做节点服务器健康检查吗
    猜你喜欢
    • 2015-11-16
    • 1970-01-01
    • 2014-04-04
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 2017-05-10
    • 2016-10-11
    • 2016-12-03
    相关资源
    最近更新 更多