We're using AWS ElasticBeanstalk to serve our Ruby on Rails application and have recently enabled auto scaling. The auto scaling works as expected but there is a brief period of time where immediately following the auto scaling, some of the new instances cause 502 Bad Gateway errors to be returned.

After a few minutes, the instances start working as expected. I'm not sure what is causing this I don't know what to do to prevent this from happening.

My hunch is that the instance is being put into service on the ELB before the RoR application is running but nginx doesn't know that. Is there something I can do to check that and prevent it?


It turns out that this was because of a misconfiguration in the ELB. It had an incorrect health check URL which was returning 200 regardless of the RoR status. As such, this was telling the ELB that this EB instance was ready and was put in service before actually being ready, and therefor causing 502s.

Setting the ELB health check URL to a correct URL that returned something other than 200 prevented EB instances from being put into service on the ELB and solved this problem.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.