EthioDeploy
DocsPricingDomainsBlogToolsChangelog

Blog/Fix deploy errors

Django DisallowedHost and CSRF errors behind a proxy

BS
Brook SolomonPublished November 15, 2026
Share on XShare on LinkedIn
Invalid HTTP_HOST header

THE SHORT ANSWER

DisallowedHost means the request's Host header isn't in ALLOWED_HOSTS, so Django answers 400; add your production domain to the list. The CSRF 403 "Origin checking failed - https://... does not match any trusted origins" usually means Django thinks the request came over plain HTTP: the proxy ended HTTPS and forwarded it as HTTP, so Django expects an http:// origin and the browser sent https://. Set SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https") when your proxy sets that header. Since Django 4.0, entries in CSRF_TRUSTED_ORIGINS must include the scheme, such as https://example.com.

What do the two errors look like?

The first one shows up as a plain Bad Request (400) page on every URL, with this in the logs:

Invalid HTTP_HOST header: 'myapp.ethiodeploy.app'. You may need to add 'myapp.ethiodeploy.app' to ALLOWED_HOSTS.

The second only appears on forms and other POST requests, the admin login being the usual first victim. The browser shows Forbidden (403), “CSRF verification failed. Request aborted.”, and the log names the reason:

Forbidden (Origin checking failed - https://myapp.ethiodeploy.app does not match any trusted origins.): /admin/login/

Both pass on localhost because runserver sees the request directly over HTTP, and with DEBUG = True and an empty ALLOWED_HOSTS, Django accepts .localhost, 127.0.0.1 and [::1]. In production you have a real domain, DEBUG = False, and a proxy between the browser and Django.

How do I fix DisallowedHost?

ALLOWED_HOSTS lists the host names your site answers to. Django compares each request's Host header against it, ignoring the port, and raises DisallowedHost when nothing matches. Django's docs on DEBUG: with it off and ALLOWED_HOSTS unset, “all requests” are returned as “Bad Request (400)”. Read the list from the environment so each deploy can have its own:

# settings.py
import os

ALLOWED_HOSTS = [h for h in os.environ.get("ALLOWED_HOSTS", "").split(",") if h]
ALLOWED_HOSTS=myapp.ethiodeploy.app,example.com,www.example.com
  • Use host names only: no https://, no path, no port. The error message quotes the exact value Django saw, so copy it from there.
  • A leading dot matches the domain and every subdomain: .example.com covers example.com and www.example.com.
  • "*" matches anything, and the docs say you are then responsible for validating the Host header yourself. Don't use it to make the error go away.
  • Keep the platform address in the list after adding a custom domain if your host's health checks use it.

Why does CSRF fail only behind a proxy?

Since Django 4.0, the CSRF middleware checks the browser's Origin header on POST requests. In Django's source, it builds the origin it expects from two parts: https if request.is_secure() is true, otherwise http, plus the host from request.get_host(). If that string equals the Origin header, the request passes. If not, Django falls back to CSRF_TRUSTED_ORIGINS, and when nothing matches you get “Origin checking failed”.

Now add a proxy. Most platforms end HTTPS at a load balancer and forward the request to your app over plain HTTP. Django sees an HTTP connection, so is_secure() is false and the expected origin becomes http://myapp.ethiodeploy.app. The browser, which really is on HTTPS, sends Origin: https://myapp.ethiodeploy.app. One letter apart, and the request is rejected. That is why the error message shows an https:// origin that looks exactly like your site.

So the fix is usually not CSRF_TRUSTED_ORIGINS at all. It is telling Django the request was secure.

How do I set SECURE_PROXY_SSL_HEADER?

Proxies that end HTTPS normally pass the original scheme in an X-Forwarded-Proto header. Tell Django to read it:

# settings.py
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True

The header name is written the way it appears in request.META: upper case, dashes turned into underscores, with HTTP_ in front. When the value is https, or a comma-separated list whose leftmost entry is https, is_secure() returns true, the expected origin becomes https://... and same-site form posts pass.

Django's docs warn that this setting can compromise your site if the proxy doesn't control the header. Set it only when all of these are true: your app is behind a proxy, the proxy strips any X-Forwarded-Proto a client sends, and the proxy sets the header itself. If a client could reach Django directly with a forged header, it could claim to be on HTTPS.

Fixing is_secure() also fixes other things that read it: request.build_absolute_uri() starts generating https:// links, and SECURE_SSL_REDIRECT = True stops redirecting in a loop, since without the header Django thinks every request is HTTP.

When do I need CSRF_TRUSTED_ORIGINS?

When a POST legitimately comes from an origin other than the one being served: a frontend on app.example.com posting to api.example.com, or a proxy setup where Django can't see the real host or scheme. Django 4.0 changed the format. The release notes: “Values in the CSRF_TRUSTED_ORIGINS setting must include the scheme (e.g. 'http://' or 'https://') instead of only the hostname.”

# Django 4.0 and later
CSRF_TRUSTED_ORIGINS = [
    "https://example.com",
    "https://*.example.com",  # every subdomain
]

An old entry without a scheme fails a system check, so manage.py commands such as migrate and runserver refuse to run:

?: (4_0.E001) As of Django 4.0, the values in the CSRF_TRUSTED_ORIGINS setting must start with a scheme (usually http:// or https://) but found example.com. See the release notes for details.

The old .example.com form for subdomains became https://*.example.com. A common way to keep both settings in step is to derive the origins from ALLOWED_HOSTS:

CSRF_TRUSTED_ORIGINS = [f"https://{h}" for h in ALLOWED_HOSTS if not h.startswith(".")]

Adding your own domain here also makes the 403 go away when SECURE_PROXY_SSL_HEADER is missing, because the https:// origin now matches the trusted list. That hides the real problem: is_secure() is still false, so absolute URLs still say http://. Fix the proxy header first.

Do I need USE_X_FORWARDED_HOST?

Only if your proxy replaces the Host header. Some setups forward every request with the upstream's internal name, such as Host: 127.0.0.1:8000 or a container name, and put the original in X-Forwarded-Host. Then DisallowedHost names an internal address, and the CSRF check compares the browser's origin with that internal host.

You can fix it in either place. In the proxy, pass the original host through (in Nginx, proxy_set_header Host $host;). Or in Django:

USE_X_FORWARDED_HOST = True

Django then prefers X-Forwarded-Host over Host, and ALLOWED_HOSTS is checked against it. The docs say to enable it only “if a proxy which sets this header is in use”. USE_X_FORWARDED_PORT does the same for the port; USE_X_FORWARDED_HOST takes priority when both are on. If the proxy already keeps the original Host, leave both off.

The 403 names a different reason

The text in parentheses tells you which check failed. The other common ones:

  • CSRF cookie not set. The browser didn't send the csrftoken cookie, for example because the form page came from a different domain than the one it posts to.
  • CSRF token missing. The form has no {% csrf_token %}, or a JavaScript call doesn't send the X-CSRFToken header.
  • Referer checking failed - no Referer. On a secure request without an Origin header, Django requires a Referer. A Referrer-Policy: no-referrer header on your pages can strip it.
  • Referer checking failed - https://... does not match any trusted origins. The same mismatch as the Origin case, on a request that sent only a Referer.

What does EthioDeploy need?

HTTPS ends at EthioDeploy's proxy, which forwards the request to your container over HTTP with an X-Forwarded-Proto header and keeps the original Host header. So a Django app here needs two settings and no more:

  • ALLOWED_HOSTS with your <project-slug>.ethiodeploy.app address and any custom domain, set as an environment variable.
  • SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https").

USE_X_FORWARDED_HOST isn't needed, since the host arrives unchanged. Add CSRF_TRUSTED_ORIGINS only for cross-origin posts.

The deploy health check is sent with Host: <project-slug>.ethiodeploy.app. If that address is missing from ALLOWED_HOSTS, Django answers the check with a 400 and the deploy fails, even when your custom domain is listed. The full settings file is in the Django deploy guide; static files are covered in Django static files 404 in production.

Questions

The request's Host header isn't in ALLOWED_HOSTS, so Django raised DisallowedHost and answered 400. Add the host name the message quotes, without scheme or port, to ALLOWED_HOSTS.

Behind a proxy that ends HTTPS, Django sees plain HTTP and expects an http:// origin while the browser sends https://. Set SECURE_PROXY_SSL_HEADER to trust the proxy's X-Forwarded-Proto header.

Yes, since Django 4.0. Each entry must start with a scheme, such as https://example.com, and a subdomain wildcard is written https://*.example.com. Entries without a scheme fail system check 4_0.E001.

Only if you validate the Host header yourself, which Django's docs say becomes your responsibility. Otherwise list the real domains.

Only when your proxy replaces the Host header and sends the original in X-Forwarded-Host. If the proxy keeps the original Host, leave it off.

Sources

Checked on November 15, 2026:

  • Django: Settings reference
  • Django 4.0 release notes
  • Django source: CSRF middleware
  • Django source: HttpRequest.get_host
  • Django source: 4_0.E001 check

Push a repo. Get a URL.

  • Deploy a Django app
  • Custom domains
  • Environment variables
  • Troubleshooting deploys
Start free

Join the EthioDeploy Telegram

Release notes as they ship, plus deploy help from the team and other developers.

Join on Telegram
BS
WRITTEN BYBrook SolomonFounder, EthioDeploy

Brook Solomon founded EthioDeploy and builds its deploy pipeline, build servers and AI coding agent. The posts here come from errors seen in real deploys on the platform.

All posts by Brook →
On this page
  • What do the two errors look like?
  • How do I fix DisallowedHost?
  • Why does CSRF fail only behind a proxy?
  • How do I set SECURE_PROXY_SSL_HEADER?
  • When do I need CSRF_TRUSTED_ORIGINS?
  • Do I need USE_X_FORWARDED_HOST?
  • The 403 names a different reason
  • What does EthioDeploy need?
  • Questions
  • Sources
0% read

Keep reading

  • 53300

    Fix deploy errorsNov 17, 2026

    Postgres "too many connections" after deploy: how to fix it

    Postgres refuses new connections with "FATAL: sorry, too many clients already" (SQLSTATE 53300, too_many_connections) once every slot under max_connections is taken, and max_connections defaults to 100. After a deploy the usual cause is arithmetic: each process of your app opens its own pool (10 for node-postgres and Prisma 7, 15 for SQLAlchemy), you run several processes, and for a short time the old and the new copy of the app are both connected. Count connections in pg_stat_activity, make copies × processes × pool max fit under the limit with room to spare, release clients you check out, set idle_in_transaction_session_timeout, and put PgBouncer in front when the numbers can't fit.

  • NEXT_PUBLIC_*

    Fix deploy errorsNov 17, 2026

    NEXT_PUBLIC_ env variables undefined in production: causes and fixes

    A NEXT_PUBLIC_ variable is undefined in production when it wasn't set while next build ran. Next.js replaces every process.env.NEXT_PUBLIC_ reference with a fixed value during the build, so a variable added to the server afterwards changes nothing until you build again. The other usual causes are reading it dynamically (process.env[name] or a copy of process.env), a name without the NEXT_PUBLIC_ prefix in a Client Component, and one Docker image promoted across environments. For values that must change without a rebuild, read them on the server at request time and pass them down.

  • npm error code ERESOLVE

    Fix deploy errorsNov 15, 2026

    npm ERESOLVE peer dependency error on deploy

    ERESOLVE means a package's peerDependencies range doesn't accept the version your project already uses, and npm 7 and later refuse to build that tree. It often passes locally because your package-lock.json was made with --legacy-peer-deps, your ~/.npmrc sets legacy-peer-deps=true, or your local npm is older, while the build server runs a clean npm ci without any of that. Fix it by upgrading the package to a version whose peer range fits, by forcing the version with overrides in package.json, or, as a last resort, by committing legacy-peer-deps=true in a project .npmrc so every install, local and on deploy, resolves the same way.

EthioDeploy

Agentic first development and deployment, started in Ethiopia, built for developers everywhere.

Telegram community
Product
PricingAI coding agentAgent mode docsDomainsCLIFree backend hostingHosting in EthiopiaChangelog
Deploy guides
Next.jsNode.jsPythonSvelteKitTanStack StartAstroNuxtReact RouterHonoStrapiDjangoFastAPIFlaskStreamlitExpressNestJSLaravelRailsGoTelegram botDiscord botLovableBoltReplitv0Google AI StudioBase44Firebase StudioClaude Code & Cursor
Compare
vs Herokuvs Vercelvs Rendervs Railwayvs Fly.iovs Netlifyvs KoyebHeroku alternativesVercel alternativesNetlify alternativesRender alternativesRailway alternativesFly.io alternativesReplit alternativesPythonAnywhere alternativesDigitalOcean App Platform alternativesGlitch alternatives
Resources
DocsBlogFree toolsAboutSupportContactllms.txt
© 2026 EthioDeployPay by card in USD or bank transfer in ETBTermsPrivacy