Nginx gives django static status 200 inside docker, but it is not shown
I have a static directory in my nginx container and when I go to http://localhost/admin it gives me
nginx | 1.1.1.1 - - [10/Dec/2024:12:41:17 +0000] "GET /static/admin/css/base.css HTTP/1.1" 200 21544 "http://localhost/admin/login/? next=/admin/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
but it doesn’t show up, what’s the error? P.S
in developer mode in Networks I see loaded static, I cleared the cache, in my html there is {% load static %}
docker-compose:
django:
container_name: django
build:
context: django
command: gunicorn -w 4 --bind 0.0.0.0:9000 src.wsgi:application
working_dir: /django/src
volumes:
- ./django:/django
- static_volume:/django/src/static
env_file:
- django/.env
depends_on:
- django_postgres
ports:
- "9000:9000"
nginx:
image: nginx:latest
container_name: nginx
ports:
- "80:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- static_volume:/static
depends_on:
- django
environment:
- NGINX_LOGGING_STDOUT=true
volumes:
static_volume:
nginx.conf
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name localhost;
location /static/ {
alias /static/;
access_log /dev/stdout;
error_log /dev/stderr debug;
}
location /favicon.ico {
access_log off;
return 204;
}
location ~* \.map$ {
log_not_found off;
access_log off;
}
location / {
proxy_pass http://django:9000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
error_log /var/log/nginx/error.log debug;
}
}
settings.py
DEBUG = False
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, STATIC_URL)
]
STATIC_ROOT = 'src/static/'
inside nginx container
bin boot dev docker-entrypoint.d docker-entrypoint.sh etc home lib lib64 media mnt opt proc root run sbin srv static sys tmp usr var
inside static
drwxr-xr-x 8 root root 4096 Dec 10 12:01 .
drwxr-xr-x 1 root root 4096 Dec 10 12:31 ..
drwxr-xr-x 4 root root 4096 Dec 10 12:01 Layer
-rwxr-xr-x 1 root root 0 Dec 9 13:21 __init__.py
drwxr-xr-x 5 root root 4096 Dec 10 12:01 admin
drwxr-xr-x 5 root root 4096 Dec 10 12:01 django_extensions
drwxr-xr-x 7 root root 4096 Dec 10 12:01 leaflet
drwxr-xr-x 10 root root 4096 Dec 10 12:01 main
drwxr-xr-x 7 root root 4096 Dec 10 12:01 rest_framework
I tried changing the paths in settings, explicitly specifying
DEBUG=True,
explicitly doing
python manage.py collectstatic