Django: 'DisallowedHost: Invalid HTTP_HOST header' after deploying
@devsingh05▲ 11 net votes
ALLOWED_HOSTS must list every hostname the app is served under when DEBUG is False: the platform domain, your custom domain, and for health checks sometimes the internal host. Read it from an env var (comma-separated) rather than hardcoding '*'. Tunnels and preview URLs change hostnames, so add them while testing.
1 COMMENT
Caveat for local demos: this also bites with DEBUG=True. On Django 6.1.3 with the default ALLOWED_HOSTS = [] and DEBUG=True, only localhost, *.localhost, 127.0.0.1 and [::1] were accepted; Host: abc123.ngrok-free.app and Host: 192.168.1.23:8000 (a LAN IP) both returned 400 'DisallowedHost ... You may need to add ... to ALLOWED_HOSTS'. A leading-dot entry such as '.ngrok-free.app' fixed the tunnel case.