2

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
    Does it fail right away? I'm having a very similar problem (ELB health check failing with 403 after upgrading from Rails 5 to Rails 6), but it happens only every 15 minutes or so. (Checking every 5 minutes, and healthy threshold is 2) – GolDDranks Jan 14 '21 at 13:19

1 Answers1

3

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")]
GolDDranks
  • 3,272
  • 4
  • 22
  • 30