[Python] Django DisallowedHost Error Despite Domain Being in ALLOWED_HOSTS

Discussão em 'Python' iniciado por Stack, Julho 11, 2025.

  1. Stack

    Stack Membro Participativo

    Problem Description

    I'm getting a DisallowedHost error in my Django production environment, even though the domain is clearly listed in my ALLOWED_HOSTS setting. I am using traefik.

    Error Message:

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


    Current Configuration:

    My production.py settings file includes: ALLOWED_HOSTS configuration

    ALLOWED_HOSTS = ["api.tuitionwave.com", "localhost", "127.0.0.1", "django"]

    # Trust proxy headers
    USE_X_FORWARDED_HOST = True
    USE_X_FORWARDED_PORT = True

    # Security settings
    SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
    SECURE_SSL_REDIRECT = env.bool("DJANGO_SECURE_SSL_REDIRECT", default=True)


    What I've Tried


    • Verified that api.tuitionwave.com is explicitly listed in ALLOWED_HOSTS List item


    • Confirmed the settings file is being loaded correctly


    • Checked that there are no whitespace issues in the domain name

    And here is my traefik.yml File details

    http:
    routers:
    web-router:
    rule: "Host(`api.tuitionwave.com`)"
    entryPoints:
    - web
    middlewares:
    - redirect
    service: django

    web-secure-router:
    rule: "Host(`api.tuitionwave.com`)"
    entryPoints:
    - web-secure
    middlewares:
    - default-headers
    service: django
    tls:
    # https://docs.traefik.io/master/routing/routers/#certresolver
    certResolver: letsencrypt

    Continue reading...

Compartilhe esta Página