So i have setup a laravel application and hosted on a docker which in turned hosted using AWS ECS Cluster running behind ALB.
So far i have the application up and running as expected, everything runs just the way it is (e.g. Sessions are stored in memcached and working, static assets are in S3 bucket, etc).
Right now i just have 1 problem with stability and i am not quiet sure where exactly the problem is. When i hit my URL / website, sometimes (randomly) it returns 502/503 HTTP error. When this happen i have to wait for about a minute or 2 before the app can return 200 HTTP code.
Here’s a result of doing tail on my docker (i.e. nginx log)
At this point i am totally lost and not sure where else i should check. I’ve tried the following:
- Run it locally, with the same docker / nginx >> works just fine.
- Run it without ALB (i.e. Using just 1 EC2) >> having similar problem.
- Run it using ALB on 2 different EC2 type (i.e. t2.small and micro) >> both having similar problem.
- Run it using ALB on just 1 EC2 >> having similar problem.
2
Answers
I have had a similar issue in the past for one of a couple of possible reasons;
To help fully debug, it might be worth determining whether the 502/503 is coming from the ALB or from NGINX. You might be able to determine this from the access log of the ALB or the
/var/log/nginx/access|error.log
in the container.It may also help to check, was there a response body on the response?
According to your logs, ngjnx is answering 401 Unauthorized to the ALB health check request. You have to answer 200 OK in
/
endpoint or configure a different one like/ping
in your ALB target group.To check the health of your targets using the console
More info: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/target-group-health-checks.html