# Nginx configuration for React SPA + FastAPI backend proxy # Optimized for production deployment with gzip compression and caching server { listen 80; server_name _; # Root directory for static files root /usr/share/nginx/html; index index.html; # Security headers add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; # Gzip compression for performance gzip on; gzip_vary on; gzip_min_length 1024; gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/javascript application/json application/xml image/svg+xml; # Backend proxy shared settings (used by /api/ and /categories/) # API proxy to backend service # All requests to /api/* are proxied to the backend container location /api/ { proxy_pass http://backend:8001; proxy_http_version 1.1; # Internal API key for backend authentication proxy_set_header X-API-Key changeme; # Preserve original request information 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; # Timeouts for long-running operations proxy_connect_timeout 60s; proxy_send_timeout 600s; proxy_read_timeout 600s; # Disable buffering for streaming responses proxy_buffering off; proxy_request_buffering off; } # Categories API proxy (used by CategoryManagement) location /categories/ { proxy_pass http://backend:8001; proxy_http_version 1.1; proxy_set_header X-API-Key changeme; 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_connect_timeout 60s; proxy_send_timeout 120s; proxy_read_timeout 120s; } # Static assets caching (JS, CSS, images, fonts) location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; access_log off; } # React Router - SPA fallback routing # All non-file requests return index.html for client-side routing location / { try_files $uri $uri/ /index.html; # No caching for index.html (always fetch latest) add_header Cache-Control "no-cache, no-store, must-revalidate"; add_header Pragma "no-cache"; add_header Expires "0"; } # Health check endpoint (for Coolify/Docker monitoring) location /health { access_log off; return 200 "healthy\n"; add_header Content-Type text/plain; } # Error pages error_page 404 /index.html; error_page 500 502 503 504 /index.html; # Logging access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log warn; }