Config.hosts in Rails 7

I’m having a heck of a time getting my config.hosts to work while using Rails 7.0.4.3. I have a deployed a standard set-up which I’ve done many times before, with nginx routing requests upstream to unicorn. After my initial deployment, I got the error message about a “Blocked host”.

"To allow requests to my.domain.com, add the following to your environment configuration:

config.hosts << “my.domain.com

I went ahead and added that exact line to my config/environments/production.rb file and redeployed. I’ve confirmed many times the app is running in production. But no matter what I do, I get the blocked hosts message.

I even went so far as to edit the actual gem code in my bundle, which is in the ActionDispatch::HostAuthorization class (identical to here: rails/host_authorization.rb at 7-0-stable · rails/rails · GitHub). I just have #authorized? return true no matter what.

Still no dice. I tried many variants of the configuration … config.hosts.clear, I tried to except certain request.paths, etc. Nothing works.

Any suggestions?

Oh, I should add, when I start the app via the console on the server, and inspect the configuration, the host I need is in there:

Rails.configuration.hosts

=> [“my.domain.com”]

Have you tried adding config.hosts << 'localhost' ?

Thanks … I hadn’t, and it was certainly worth a shot. But didn’t work, either.

I feel like there is some odd caching behavior happening. I even kill unicorn, so the app itself isn’t running, and I still get that same Blocked Hosts response – even after I clear my browser cache.

@timgut Did you solve it at the end?

I am having the very same problem now and I tried everything.

What is your setup on the server? Are you running this via docker? Also, what is handling your networking?

Sorry, I was never able to actually. Very confusing issue.

You may have other rails services running at the same time. I fix it after stopt other puma service, and restart from console