I know there are many such questions. But I’ve tried a lot of what I’ve found and nothing helps.
I have a combination of Django + uWSGI + Nginx + PostgreSQL.
Static file was collected by python manage.py collectstatic
in movies_admin/static directory.
I’m logging into Django admin at a local address via nginx 127.0.0.1/admin. The page itself is loaded, but only the text, fields and the like. No graphics – that my problem.
My docker-compose file:
version: '3'
services:
django:
restart: always
build: movies_admin/.
env_file:
- .env
ports:
- "8000:8000"
container_name: work_django
depends_on:
- postgres
postgres:
restart: always
env_file:
- .env
image: 'postgres:${PG_VER}'
environment:
- POSTGRES_DB=${DB_NAME}
- POSTGRES_USER=${DB_USER}
- POSTGRES_PASSWORD=${DB_PASSWORD}
container_name: work_database
ports:
- "5432:5432"
volumes:
- ${DB_VOLUME_CATALOG_PATH}:/var/lib/postgresql/data/
nginx:
image: 'nginx:${NGINX_VER}'
volumes:
- ${NGINX_CONF_FILE}:/etc/nginx/nginx.conf:ro
- ${NGINX_CONFD_CATALOG}:/etc/nginx/conf.d:ro
- ${STATIC_PATH}:/var/www/static/:ro
container_name: work_nginx
depends_on:
- django
ports:
- "80:80"
I checked. The static directory is mounted in the ‘/var/www/static/’ directory of the nginx container.
My site.conf:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location /static/ {
alias /var/www/static/;
}
location @backend {
proxy_pass http://django:8000;
}
location ~* .(?:jpg|jpeg|gif|png|ico|css|js)$ {
log_not_found off;
expires 90d;
}
location / {
try_files $uri @backend;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Part of my settings.py:
STATIC_ROOT = '/var/www/static'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static/'),
'/opt/app/static/',
]
STATIC_URL = '/static/'