skip to Main Content

In the Azure app service
my Website is working fine with something.azurewebsites.net with the following code

ALLOWED_HOSTS = [os.environ['WEBSITE_HOSTNAME']] if 'WEBSITE_HOSTNAME' in os.environ else []

But while adding a custom domain, it is showing as Bad Request (400). I think the problem relies on the Allowed host, and the Django app is not allowing my custom domain. I couldn’t find a solution or a perfect line of code to resolve this issue.

2

Answers


  1. Chosen as BEST ANSWER
    ALLOWED_HOSTS = [os.environ['WEBSITE_HOSTNAME'],os.environ['CUSTOM_HOSTNAME']]
    

    CUSTOM_HOSTNAME should be added to the application configuration in azure.

    Eg: CUSTOM_HOSTNAME: www.example.com


  2. Have you set up the custom domain in Azure? To do this, you can follow the steps in the Azure documentation:

    https://docs.microsoft.com/en-us/azure/app-service/configure-custom-dns-web-site#map-a-custom-dns-name-to-an-azure-web-app

    This will involve adding a CNAME record for your custom domain that points to your Azure app’s default domain.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search