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.
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: