Django admin redirects behind nginx proxy subpath

361 views
Skip to first unread message

Rodolphe Gohard

unread,
Oct 19, 2021, 3:37:04 PM10/19/21
to Django users

I am running a small django app with django admin.
In fact, I only use django admin to edit a few models.

It works fine in local and behind a simple proxy reverse, but now I have this kind a rewrite that changes the path: (it's a nginx ingress rewrite rule for Kubernetes)

path: /diagnosis-admin(/|$)(.*) => $2

Wich means, urls such as mydomain.com/diagnosis-admin redirect to localhost/ (mind the path change.

When I try to access the admin at mydomain.com/diagnosis-admin/admin, django tries to redirect to mydomain.com/admin/, which leads nowhere because it falls on the proxy:

    1. Request URL:
    2. Request Method:
      GET
    3. Status Code:
      301
    4. Remote Address:
    5. Referrer Policy:
      strict-origin-when-cross-origin
  1. Response Headers
    1. content-length:
      0
    2. content-type:
      text/html; charset=utf-8
    3. date:
      Tue, 19 Oct 2021 15:11:42 GMT
    4. location:
      /admin/
    5. script_name:
      /diagnosis-admin
    6. strict-transport-security:
      max-age=15724800; includeSubDomains
    7. x-content-type-options:
      nosniff

I had this problems with other applicative frameworks but could solve it since they can interpret the FORWARDED_HOST, FORWARDED_PORT and FORWARDED_PATH headers provided by the proxy.

Searching the internets gave me tons of solutions for reverse proxy with simple rewrite rules with no path alterations, but here I am stuck

I have no idea how to solve this withing django. Any help will be much appreciated


Additionnal information:
I run django with "python manage.py runserver 0.0.0.0:8000" on a docker container (running through GKE)

Everything is pretty standard, I ran the basic django project scafolding, setup the database, auto migrated the models and that's about it. I can provide additionnal files if needed



银色配色

unread,
Oct 23, 2021, 7:44:10 AM10/23/21
to Django users
I don't know but I'm interested in that

Karthik Karthik

unread,
Oct 30, 2021, 1:56:49 PM10/30/21
to Django users
yaa
Reply all
Reply to author
Forward
0 new messages