# Production Nginx Configuration for FibDash # Single backend server serving both API and static files upstream fibdash_backend { server 127.0.0.1:5000; keepalive 32; } server { listen 80; server_name fibdash.local fibdash.growheads.de your-domain.com; # Security headers add_header X-Frame-Options DENY; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header Referrer-Policy "strict-origin-when-cross-origin"; add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' https://accounts.google.com https://apis.google.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: https:; connect-src 'self' https://accounts.google.com;"; # Enable gzip compression gzip on; gzip_vary on; gzip_min_length 1024; gzip_proxied any; gzip_comp_level 6; gzip_types text/plain text/css text/xml text/javascript application/json application/javascript application/xml+rss application/atom+xml image/svg+xml; # Static assets with long-term caching location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { proxy_pass http://fibdash_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; # Cache static assets for 1 year expires 1y; add_header Cache-Control "public, immutable"; # Optional: serve from nginx cache proxy_cache_valid 200 1y; proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; } # API routes location /api/ { proxy_pass http://fibdash_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; # API responses shouldn't be cached add_header Cache-Control "no-cache, no-store, must-revalidate"; add_header Pragma "no-cache"; add_header Expires "0"; # Increase proxy timeouts for API calls proxy_connect_timeout 60s; proxy_send_timeout 60s; proxy_read_timeout 60s; } # Health check location /health { access_log off; proxy_pass http://fibdash_backend; proxy_set_header Host $host; } # All other requests (React app) location / { proxy_pass http://fibdash_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; # Cache HTML for a short time expires 1h; add_header Cache-Control "public, must-revalidate"; } # Error pages error_page 404 /404.html; error_page 500 502 503 504 /50x.html; # Logging access_log /var/log/nginx/fibdash_prod_access.log; error_log /var/log/nginx/fibdash_prod_error.log warn; } # Optional: HTTPS redirect # server { # listen 80; # server_name your-domain.com; # return 301 https://$server_name$request_uri; # } # Optional: HTTPS configuration # server { # listen 443 ssl http2; # server_name your-domain.com; # # ssl_certificate /path/to/your/certificate.crt; # ssl_certificate_key /path/to/your/private.key; # ssl_protocols TLSv1.2 TLSv1.3; # ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384; # ssl_prefer_server_ciphers off; # # # ... rest of configuration same as above # }