DisallowedHost 🐍 Python

django.core.exceptions.DisallowedHost: Invalid HTTP_HOST header: 'x'. You may need to add 'x' to ALLOWED_HOSTS.

The request’s Host header isn’t listed in Django’s ALLOWED_HOSTS.

Seen on: Python

Meaning

With DEBUG=False, Django only serves hosts in ALLOWED_HOSTS. New domains, server IPs, load balancer health checks and container hostnames must be added.

Common causes

  • New domain/IP not in ALLOWED_HOSTS
  • Load balancer health checks using the instance IP
  • Proxy not forwarding the Host header

⚡ Quick fix

  1. Add the domain(s): ALLOWED_HOSTS = ["example.com", "www.example.com"]
  2. Read from an env var per environment
  3. Configure the proxy to pass Host

Detailed fix by platform

Python

  1. ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "").split(",")

How to diagnose

  1. Host — Which host is in the message?
  2. Source — Real users or health checks?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.