skip to Main Content

I have a reactjs frontend stored on an s3 bucket (and is accessible through cloudfront) and I have a springboot backend running on an EC2 instance.

The ReactJs frontend uses an HTTPs protocol and has an SSL certificate attached to it. And in order to connect to the backend I send a HTTPS api which connects to an Application Load Balancer and connects to the target group on the 80 group so that the springboot application can get the request.

However, whenever I send the first request I get a 502 "Bad Gateway" and then when I send a second request I get a 200 success response. And then this repeats (the third request gives 502 and the fourth request gives 200). I utilized Postman to test this.

I have been stuck on this for quite a while so I would appreciate any kind of help.

I have tried adding
server.tomcat.connection-timeout=300000 server.tomcat.keep-alive-timeout=300000
to the application.properties in the springboot app but that does not work.

2

Answers


  1. That sounds exactly like one of the 2 servers is broken and the load balancer does round robin between them. Every seconds request succeeds as it hits the good node.

    Start with directly invoking the nodes skipping the loadbalancer. One of them must be closed or failed to initialize.

    Login or Signup to reply.
  2. Try to check Security Group and NACL:

    Take a look if EC2 instance’s security group allows incoming traffic on port 80 (HTTP) and 443 (HTTPS). You can try this in the AWS Management Console or AWS CLI commands.

    AWS CLI command:

    bash

    aws ec2 authorize-security-group-ingress --group-id YOUR_SECURITY_GROUP_ID --protocol tcp --port 80 --cidr YOUR_IP_RANGE
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search