I have a django backend and react frontend.
I want to serve the react on / and use /admin, /api and /auth for Django. Here's what I have in my Nginx.
upstream backend {
    server 127.0.0.1:8000;
}
server {
    listen 80;
    server_name x.x.x.x;
    root /home/user/folder/frontend;
    index index.html index.htm;
    # for serving static
    location /static {
        alias /home/user/folder/backend/staticfiles;
    }
    # for serving react built files
    location / {
        try_files $uri $uri/ /index.html;
    }
    
    # for everything django
    location ~^/(admin|api|auth) {
      include snippets/proxyinfo.conf;
      proxy_pass http://backend;
    }
}
With the above, the expected behavior is
- /uses the default root folder,- /home/user/folder/frontendand loads the built index files from react accordingly
- /(admin|api|auth)points to django
- /staticloads static files saved in the- /home/user/folder/backend/staticfilesfolder.
So not sure why when I hit example.com/static/myfile.css, Nginx is going to /home/user/folder/frontend/static/myfile.css
I'd expect none of the above configuration says that's what it should do, so what magic is going on?
I thought this answer was self explanatory enough, yet Nginx keeps doing whatever it likes.
I'm using nginx/1.18.0 (if that matters)
 
     
    