Unblocking Azure domain to configure middleware for Rails app

Alexander, Carmen 20 Reputation points
2024-02-28T16:31:12.1966667+00:00

I believe this is a Rails problem, but in case there might be a fix on the Azure side, I wanted to ask this question here. I'm developing a Rails application. I created a Web App on Azure so that the Rails app can be accessed by others for testing purposes. I got everything configured as far as Azure goes, but when I try to log on the web app, I get a blocked host error: Blocked hosts:

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,953 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Grmacjon-MSFT 19,151 Reputation points Moderator
    2024-03-04T22:49:09.76+00:00

    Hello @Alexander, Carmen the "Blocked hosts" error in your Rails application deployed on Azure likely stems from a security configuration within the framework. This is due to Rails’ host authorization middleware, which is designed to prevent against DNS rebinding attacks. By default, Rails only allows requests from localhost in the development environment. When you deploy your application to Azure, the host will be different, hence the error.

    To resolve this issue, you need to add your Azure domain to the allowed hosts in your Rails configuration:

    • Open the file config/environments/development.rb (or the appropriate environment file based on your configuration).
    • Locate the config.hosts configuration block.
    • Add your Azure app's domain name within the block using single quotes. If you need to allow multiple domains, add each domain name on a separate line within the block.

    Here's an example code snippet:

    Rails.application.config.hosts << 
    "<web app name>.azurewebsites.net"
    
    

    Replace <web app name> with the actual name of your web app on Azure

    After making changes to config.hosts or using environment variables, remember to restart your Rails server for the changes to take effect. Lastly, make sure the domain listed in config.hosts or the environment variable matches the domain used to access your Azure app exactly.

    Best,

    Grace

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.