Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Load Balancing a Node.js App on port 3000

I've got a Node.js Express web app that is using the default port 3000 and responds fine on an Ubuntu EC2 instance by elastic ip. I'm trying to setup Load Balancing built into AWS and can't seem to get a good health check to pass

Setup 2 ubuntu servers that server the app fine on port 3000.

Set the load balancer listeners for port 80 to route to Instance port 3000 and also tried routing 3000 to 3000.

Added the amazon-elb/amazon-elb-sg security group to my instance security groups just in case.

Set the health check to port 80 and 3000 to many valid urls within the project.

Anything I'm missing here?

UPDATE:

Turns out it was the simplest thing I was overlooking. Somehow my actual instances were in a security group with only 80 opened and I just had to add a rule to open 3000. Can't believe I missed that.

like image 584
Patrick Kafka Avatar asked Sep 26 '12 02:09

Patrick Kafka


People also ask

Does AWS application load balancer support TCP?

A: Yes. Network Load Balancers support both TCP, UDP, and TCP+UDP (Layer 4) listeners, as well as TLS listeners.

How does node js handle load balancing?

To configure load balancing, you first create a named “upstream group,” which lists the backend servers. You then set up NGINX Open Source or NGINX Plus as a reverse proxy and load balancer by referring to the upstream group in one or more proxy_pass directives. Configure an upstream group called nodejs with two Node.

Which listening port should you configure on the load balancer?

For Load Balancer Protocol, select HTTPS (Secure HTTP). This updates Load Balancer Port, Instance Protocol, and Instance Port. By default, the instance protocol is HTTP. If you want to set up back-end instance authentication, change the instance protocol to HTTPS (Secure HTTP).

How do I open port 3000?

Hi Cezary, You can run this command http-server -p 3000 and then open your browser and type in localhost:3000 or 127.0. 0.1:3000 in the address bar.


1 Answers

If you have the load balancer set up only to forward incoming requests on port 80 to port 3000 on the backend instances, then you shouldn't get any response when trying ports other than 80. If you are making the requests against port 3000 (i.e. http://yourdomain.com:3000/uri) you need to have your load balancer also forward incoming requests on port 3000 to port 3000 on the instances.

If you are using only port 3000 on the instances, then you need to make sure your health check points to port 3000. (i.e. TCP ping 3000, or HTTP to port 3000 against your /ping service).

like image 91
Mike Brant Avatar answered Sep 19 '22 04:09

Mike Brant