Using Ngrok and Rails 6

If you try to use ngrok with Rails 6 you will find that whatever tries to connect to your app via the ngrok url will receive the following error:

To allow requests to, add the following to your environment configuration: config.hosts << “”

This is because Rails 6 introduces a little extra security to prevent attacks and will only allow and localhost to connect. To allow a different host to access the app you simply need to update your config/environments/development.rb file and add one of the following lines:

config.hosts = nil

config.hosts << /[a-z0-9]+\.ngrok\.io/


config.hosts << ""

The former will allow all hosts. For most people this is probably fine. But if you require more security you can use the second approach and provide a regexp to allow only ngrok addresses. The last approach provides a hardcoded host which is good when the host rarely changes.