Skip to content

Troubleshooting · By Rivtor · Updated

Fix Django DisallowedHost after deployment

Django DisallowedHost means the request host did not match the application’s allowed-host configuration. Add the intended hostname using Django’s supported format and verify proxy behaviour. Keep this separate from CORS, CSRF and authentication errors.

See the Rivtor deployment workflow →

Inspect the actual request host

Check the sanitized exception and the hostname used by the browser or health probe. ALLOWED_HOSTS entries normally describe hostnames, not full URLs with a scheme and route. A new custom domain or a provider health hostname can expose a mismatch that did not appear locally.

Do not set DEBUG=True on a public service to make the deployment easier to inspect. Do not add an unrestricted wildcard as the default response to a rejected host.

Configure the intended boundary

For an illustrative settings fragment where the deployment hostname is supplied privately:

import os
ALLOWED_HOSTS = [value.strip() for value in os.environ.get('APP_ALLOWED_HOSTS', '').split(',') if value.strip()]

Set APP_ALLOWED_HOSTS to the intended hostnames through the host’s environment workflow. This is only host validation, not a complete production settings module. Check the installed Django release’s documentation for subdomain and proxy behaviour.

ConditionRelevant boundary
Host rejected before normal handlingALLOWED_HOSTS
Browser cannot read another originCORS configuration
Cookie-authenticated write refusedCSRF configuration and credentials
Wrong scheme in redirectsTrusted proxy/TLS configuration

Do not trust arbitrary forwarded-host or forwarded-proto headers from unknown callers. Only configure Django to trust a proxy when the deployment boundary ensures that proxy controls the relevant header.

Verify public and health requests

On Rivtor, inspect the assigned service hostname and service configuration. Add the custom domain through the documented workflow before expecting it to route to the application. Check whether health probes use the same hostname or require a documented configuration adjustment.

After the fix, request the intended public URL, inspect redirects and exercise a synthetic write through the deployed browser flow. In a controlled test, confirm an unexpected hostname is still rejected. A successful health check does not establish CORS, CSRF or record authorization, so keep those acceptance checks distinct.

References