fix(docker): serve django static files via nginx

This commit is contained in:
bisco
2026-04-29 18:46:53 +02:00
parent c82103cc66
commit 784076e6be
3 changed files with 10 additions and 4 deletions

View File

@@ -112,7 +112,8 @@ DEFAULT_FROM_EMAIL = os.environ.get("DEFAULT_FROM_EMAIL", "no-reply@azionelab.lo
if "test" in sys.argv:
EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
STATIC_URL = "static/"
STATIC_URL = "/static/"
STATIC_ROOT = BASE_DIR / "staticfiles"
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
REST_FRAMEWORK = {

View File

@@ -19,11 +19,14 @@ services:
POSTGRES_PORT: ${POSTGRES_PORT:-5432}
expose:
- "${BACKEND_PORT:-8000}"
volumes:
- django_static:/app/staticfiles
depends_on:
postgres:
condition: service_healthy
networks:
- internal
user: "0:0"
restart: unless-stopped
frontend:
@@ -66,6 +69,7 @@ services:
NGINX_ENVSUBST_FILTER: "^(BACKEND_HOST|BACKEND_PORT|FRONTEND_HOST|FRONTEND_PORT)$"
volumes:
- ./nginx/templates:/etc/nginx/templates:ro
- django_static:/var/www/static:ro
depends_on:
- backend
- frontend
@@ -75,6 +79,7 @@ services:
volumes:
postgres_data:
django_static:
networks:
internal:

View File

@@ -29,9 +29,9 @@ server {
}
location /static/ {
proxy_pass http://azionelab_backend;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
alias /var/www/static/;
access_log off;
expires 1d;
}
location /media/ {