Статические файлы в контейнере с django и nginx не подгружаются!
Не могу найти причину, почему упорно не подгружается статика в контейнере...
docker-compose.yml
volumes:
pgdata:
static:
media:
services:
postgres:
image: postgres:16
container_name: postgres
restart: always
env_file:
- ./env/.env.db
volumes:
- pgdata:/var/lib/postgresql/data/
django:
build:
context: .
container_name: django
expose:
- "8000"
- "587"
ports:
- "8000:8000"
env_file:
- ./env/.env.dev
volumes:
- ./:/app
- static:/app/static
- media:/app/media
command: sh -c "python3 manage.py collectstatic --noinput &&
python3 manage.py makemigrations &&
python3 manage.py migrate &&
gunicorn --workers=4 --reload --max-requests=1000 userauth.wsgi -b "0.0.0.0:8000""
depends_on:
- postgres
- redis
nginx:
build:
context: ./nginx
dockerfile: Dockerfile
container_name: nginx
working_dir: /app
restart: always
ports:
- "80:80"
volumes:
- ./:/app
- static:/app/static
- media:/app/media
depends_on:
- django
redis:
image: redis:latest
container_name: redis
env_file:
- ./env/.env.dev
expose:
- "6379"
volumes:
- ./redis/data:/data
celery-worker:
build: .
restart: always
container_name: celery-worker
env_file:
- ./env/.env.dev
volumes:
- ./:/app
- media:/app/media
command: celery -A userauth worker --loglevel=info --logfile=./logs/celery-worker.log
depends_on:
- redis
celery-beat:
build: .
container_name: celery-beat
env_file:
- ./env/.env.dev
command: celery -A userauth beat --loglevel=info --logfile=./logs/celery-beat.log
volumes:
- media:/app/media
- ./:/app
depends_on:
- redis
dockerfile
FROM python:3.10
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY requirements.txt /app
RUN pip install --no-cache-dir -r requirements.txt
COPY . /app
nginx.conf
server django:8000;
}
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://django;
}
location /static/ {
root /app;
}
location /media/ {
root /app;
}
}
nginx/dockerfile
FROM nginx:latest
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/
settings.py
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEBUG=True
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
в терминале:
django | Bad Request: /
django | Not Found: /static/admin/js/nav_sidebar.js
django | Not Found: /static/admin/css/nav_sidebar.css
django | Not Found: /static/admin/css/base.css
консоль браузера:
Загрузка <script> по адресу «http://127.0.0.1:8000/static/admin/js/nav_sidebar.js» не удалась.
Ресурс с «http://127.0.0.1:8000/static/admin/css/responsive.css» был заблокирован из-за несоответствия MIME-типа («text/html») (X-Content-Type-Options: nosniff).