Django : Статика, обслуживаемая с помощью nginx, не может работать Ошибка 404

Я использую homebrew для запуска служб nginx.

Каталог проекта Django :

ядро (приложение)
main_app(app)
maps(app)
static → папка css, папка js и т.д.
шаблоны
manage.py

Шаги :

  1. Я добавляю статический и медиа URL и путь
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static"),
]

STATIC_URL = '/static/'
STATIC_ROOT = '/Users/nuntea/Documents/Vasundhara Geo technology/vgt-bitmapper-portal-app/staticfiles/'

MEDIA_URL = '/media/'
MEDIA_ROOT = '/Users/nuntea/Documents/Vasundhara Geo technology/vgt-bitmapper-portal-app/media/'
  1. Затем я собираю статический
nuntea@Zonunmawias-MacBook-Air vgt-bitmapper-portal-app % python3 manage.py collectstatic 

184 static files copied to '/Users/nuntea/Documents/Vasundhara Geo technology/vgt-bitmapper-portal-app/staticfiles'
  1. Я добавляю следующий сервер
server {
    listen 8080;
    server_name _;
    
    location /static/ {
        alias /Users/nuntea/Documents/Vasundhara\ Geo\ technology/vgt-bitmapper-portal-app/staticfiles/;
    }

    location /media/ {
        alias /Users/nuntea/Documents/Vasundhara\ Geo\ technology/vgt-bitmapper-portal-app/media/;
    }
       
    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
}

в файл конфигурации

sudo nano /opt/homebrew/etc/nginx/nginx.conf

Файл nginx.conf (без комментариев):

worker_processes  1;

events {
    worker_connections  1024;
}

http {  
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    
    server {
    listen 8080;
    server_name _;
    
    location /static/ {
        alias /Users/nuntea/Documents/Vasundhara\ Geo\ technology/vgt-bitmapper-portal-app/staticfiles/;
    }

    location /media/ {
        alias /Users/nuntea/Documents/Vasundhara\ Geo\ technology/vgt-bitmapper-portal-app/media/;
    }
       
    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
  }
     include servers/*;
}

Вот дополнительная информация:

nuntea@Zonunmawias-MacBook-Air vgt-bitmapper-portal-app % nginx -t
nginx: the configuration file /opt/homebrew/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /opt/homebrew/etc/nginx/nginx.conf test is successful

nuntea@Zonunmawias-MacBook-Air vgt-bitmapper-portal-app % cat /opt/homebrew/var/log/nginx/error.log   
2024/02/01 18:45:38 [notice] 27654#0: signal process started
2024/02/01 18:52:33 [notice] 28151#0: signal process started
2024/02/01 18:54:08 [notice] 28392#0: signal process started
2024/02/01 18:57:44 [notice] 28474#0: signal process started

nuntea@Zonunmawias-MacBook-Air vgt-bitmapper-portal-app % sudo lsof -i :8080                          

COMMAND   PID   USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
nginx   27986 nuntea    6u  IPv4 0xb41b860f093f6c3d      0t0  TCP *:http-alt (LISTEN)
nginx   28476 nuntea    6u  IPv4 0xb41b860f093f6c3d      0t0  TCP *:http-alt (LISTEN)

Django start runserver

nuntea@Zonunmawias-MacBook-Air vgt-bitmapper-portal-app % python3 manage.py runserver

[01/Feb/2024 23:39:54] "GET / HTTP/1.1" 302 0
[01/Feb/2024 23:39:55] "GET /core/login-user/?next=/ HTTP/1.1" 200 1801
[01/Feb/2024 23:39:55] "GET /static/custom_css/base.css HTTP/1.1" 404 179
[01/Feb/2024 23:39:55] "GET /static/jquery_js/jquery-3.6.4.min.js HTTP/1.1" 404 179
[01/Feb/2024 23:39:55] "GET /static/bootstrap_css/bootstrap.min.css HTTP/1.1" 404 179
[01/Feb/2024 23:39:55] "GET /static/bootstrap_js/bootstrap.min.js HTTP/1.1" 404 179
Вернуться на верх