简体   繁体   中英

How to configure AWS Elastic Load Balancer's heath check for Node.js

I'm new to Node.js, my question could be stupid to someone, please forgive me for this.

In the past, I have Apache installed on an EC2 instance. I created ping.html inside this directory /var/www/html/ping.html .

And the Health Check would be: Ping Port:80 , Ping Path:/ping.html .

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.

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 */);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM