0
votes

I have a domain name myapi.example.com with CNAME pointing to my load balancer, in my load balancer I register 2 ec2 servers

Each ec2 servers have nginx configure

listen 80;
listen [::]:80;

server_name myapi.example.com;

proxy_pass http://127.0.0.1:4000;

I see that the loadbalancer is hitting my server in a round robin fashion, but if one of my server is down, the loadbalancer still hits it resulting in 502

Is there a way for the loadbalancer to detect that the server is down and reroute?

2

2 Answers

1
votes

You should configure a Health Check for the Load Balancer.

The load balancer will regularly check the health of each server (by checking whether a given page returns a 200 response).

If a server fails the health check, then the Load Balancer will stop sending requests to that server. Once the server again passes the health check, the Load Balancer will resume sending requests.

See: Health Checks for Your Target Groups - Elastic Load Balancing

0
votes

Please use Health Check in your Load balance.

The Health Check has an interval. it will stop sending in one minute if the interval is one minute.