ELB Target groups health checks are failing with 403 after upgrading from Rails 5 to rails 6

1.8k views Asked by At

ELB target group's health check is failing with status code 403 forbidden after upgraded rails to rails 6. However health check is working in development but not on AWS cloud.

Health check is succeed with rails 5 but not with rails 6.

Any help would be greatly appreciated.

1

There are 1 answers

0
GolDDranks On BEST ANSWER

This happens because of a new feature in Rails 6: host authorization. It checks whether the incoming request has correct hostname, and in case it doesn't, it returns 403.

AWS ELB doesn't set the Host header when it accesses the health check endpoint, which makes it fail.

You can fix the problem either by disabling the feature (config.hosts.clear) by adding the web server internal IP (ELB accesses it with the internal one) to the allowed hosts, like this:

  config.hosts = ["example.org", IPAddr.new("10.0.99.0/24")]