Redirects from Nginx reverse-proxyed Django ASGI server going to wrong subdirectory

I'm trying to install Etebase in a subdirectory of my Nginx webserver. (I'm also running a Pi-hole dashboard on this server in a seperate subdirectory.) Etebase is a Django app using ASGI. I'm using Uvicorn as the upstream ASGI webserver.

I've reverse-proxied the Etebase server to dan9er.internal/etesync successfully. Going directly to dan9er.internal/etesync shows an "it works!" page.

However, redirects are not being handled correctly. dan9er.internal/etesync/admin/ redirects to dan9er.internal/etesync/admin/etesync/admin/login/?next=etesync/admin/. It's adding directories, not dropping the /etesync/ directory like i've seen in other questions. (Going directly to dan9er.internal/etesync/admin/login/ works fine.)

How do I fix this so it goes to dan9er.internal/etesync/admin/login/?next=etesync/admin/? Do I need to modify something in Uvicorn, Etebase or Nginx?

Nginx config:

upstream etebase {
    server unix:///tmp/etebase_server.sock;
}

# ...

location /etesync/ {
    proxy_pass http://etebase/;
    proxy_redirect off;

    # proxy_set_header stuff...
}

# ...

Etebase config (Django):

[global]
secret_file = secret.txt
debug = false
static_root = /home/eteserver/etebase/static/
media_root = /home/eteserver/etebase/media/

[allowed_hosts]
allowed_host1 = dan9er.internal

[database]
engine = django.db.backends.sqlite3
name = db.sqlite3

Start command:

/home/eteserver/etebase/.venv/bin/uvicorn etebase_server.asgi:application --uds /tmp/etebase_server.sock --root-path etesync

Exerpt from Nginx log (the frontend server, agent string removed):

192.168.0.204 - - [08/Mar/2021:20:07:06 -0500] "GET /etesync/admin/ HTTP/1.1" 302 0 "-"
192.168.0.204 - - [08/Mar/2021:20:07:06 -0500] "GET /etesync/admin/etesync/admin/login/?next=etesync/admin/ HTTP/1.1" 404 159 "-"

Exerpt from Uvicorn log (the upstream server):

Mar 08 20:07:06 dan9er-pi3 uvicorn[23360]: INFO:      - "GET etesync/admin/ HTTP/1.1" 302 Found
Mar 08 20:07:06 dan9er-pi3 uvicorn[23360]: INFO:      - "GET etesync/admin/etesync/admin/login/?next=etesync/admin/ HTTP/1.1" 404 Not Found

Solution 1:

Looks like the route is being treated as a relative path instead of absolute. That would explain the path being appended instead of replaced.

The cause might be a missing leading slash in your --root-path argument.

Give this a try:

/home/eteserver/etebase/.venv/bin/uvicorn etebase_server.asgi:application --uds /tmp/etebase_server.sock --root-path /etesync