I'm trying to deploy a Nest.js application in ECS Fargate. I keep getting the 502 Bad Gateway error for some odd reason. All target groups report healthy state, the task reports healthy state, my security group for the load balancer allows connection on 80 and 443 port. The service segurity group allows connections from LB on port 3000 (which is the port the applicaiton runs).
From the task logs I can see the healthcheck mechanism actually logging the request and returning OK. The only thing that is probably different is that I override the PORT for the healthcheck to actually use port 3000.
The application contains no proxy inside the container, it's just a simple Nest.js API.
I have tried to set the port 3000 on the target group itself and still no luck. I have tried many things and recreated the service and LB over and over with different parameters. Tried to set the port on TG to 3000 instead of the default HTTP and HTTPS protocol ports. Can anyone shed a light on this matter, it would be much appreciated.
I managed to solve this problem. For some reason, looks like I shouldn't have created two target groups for the same service. I had:
- Target Group 1: port 80
- Target Group 2: port 443
- Listener 1: port 80, target group 1
- Listener 2: port 443, target group 2
Removing Target Group 2
and pointing the Listener 2
to Target Group 1
solved the issue.