upstream backend { server backend:5000; } server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; access_log /dev/stdout; error_log /dev/stderr; client_max_body_size 20M; # --- Django: API, admin, its static assets --- location /api/ { proxy_pass http://backend; 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; proxy_read_timeout 60s; } location /admin/ { proxy_pass http://backend; 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; } # Django's own static files (admin, DRF, swagger) via WhiteNoise. location /static/ { proxy_pass http://backend; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; } # --- user uploads, from the shared `media` volume --- location /media/ { alias /app/media/; access_log off; } # --- the SPA --- # Hashed bundles are immutable; the entry document must never be cached, # or a deploy leaves browsers asking for chunks that no longer exist. location /assets/ { add_header Cache-Control "public, max-age=31536000, immutable" always; try_files $uri =404; } location / { try_files $uri $uri/ /index.html; add_header Cache-Control "no-cache"; } }