A
A
Anton Konovalov2021-09-07 11:52:59
Django
Anton Konovalov, 2021-09-07 11:52:59

How to properly configure django admin statics in NGINX?

There is a certain server on Django/DRF + Frontend.
Requests to Django go through Gunicorn sockets.
But we also need a Dzhang admin panel, which also has statics and it also needs to be “served” somehow, but so that it does not interfere with the rest of the frontend.

Now the config for nginx looks like this:

server {
    listen 80;
    server_name demo.my-domain.com;

    client_header_timeout 3s;
    client_header_buffer_size 2k;

    location = /favicon.ico { 
        access_log off; 
        log_not_found off; 
    }

    location / {
        root /home/ubuntu/my_project/frontend/build;
        index index.html index.htm;
        try_files $uri $uri/ /index.html;
    }

    location /api/ {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }

    location /admin_panel/ {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }

    location /static/ {
       alias /home/ubuntu/my_project/static_path/;
    }
}


And it doesn't work like this.

PS Of course, the static is collected and I even saw it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Konovalov, 2021-09-08
@akonovalov

Thanks to the leading questions of the venerable dodo512 , it was possible to find out that the problem lay in the same paths of the statics of the main frontend and the statics of the Dzhang admin panel.
The problem was solved by replacing the url of the jang static in the project settings (the STATIC_URL variable) and the same url was specified in the nginx settings in the location for the jang static.

S
Stefan, 2021-09-07
@MEDIOFF

whitenoise

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question