Ajit Kholambe
Ajit Kholambe

Reputation: 59

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

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.

Upvotes: 2

Views: 2026

Answers (1)

GolDDranks
GolDDranks

Reputation: 3552

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")]

Upvotes: 3

Related Questions