server { server_name localhost; listen 80; return 301 https://$host$request_uri; } server { server_name localhost; listen 443 ssl; root /usr/share/nginx/html; index index.html index.htm; # Allow large file uploads for videos (up to 500MB) client_max_body_size 500M; ssl_certificate /etc/nginx/ssl/nginx-selfsigned.crt; ssl_certificate_key /etc/nginx/ssl/nginx-selfsigned.key; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers HIGH:!aNULL:!MD5; # API routes - proxy to backend (MUST come before static file rules) location /api/ { # Handle preflight OPTIONS requests if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '$http_origin' always; add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, X-Requested-With' always; add_header 'Access-Control-Allow-Credentials' 'true' always; add_header 'Access-Control-Max-Age' 1728000 always; add_header 'Content-Type' 'text/plain; charset=utf-8' always; add_header 'Content-Length' 0 always; return 204; } proxy_pass http://localhost:8000; 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_set_header Origin $http_origin; proxy_buffering off; # CORS headers for actual requests add_header 'Access-Control-Allow-Origin' '$http_origin' always; add_header 'Access-Control-Allow-Credentials' 'true' always; # Also set timeout for large uploads proxy_read_timeout 300s; proxy_send_timeout 300s; } # Static assets - NO CACHING for development location ~* ^/(?!api/).*\.(js|css|png|jpg|jpeg|gif|ico|svg)$ { add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0"; add_header Pragma "no-cache"; add_header Expires "0"; try_files $uri =404; } # Handle React Router - all other routes should serve index.html location / { add_header Cache-Control "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0"; try_files $uri $uri/ /index.html; } }