server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html index.htm; # Handle SPA routing (fallback to index.html) location / { try_files $uri $uri/ /index.html; } # PHP handling (if PHP files exist) location ~ \.php$ { # Uncomment below if using PHP-FPM # fastcgi_pass php:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # include fastcgi_params; # For static sites without PHP, return 404 return 404; } # Cache static assets location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot|pdf)$ { expires 1y; add_header Cache-Control "public, immutable"; } # 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 gzip on; gzip_vary on; gzip_min_length 1024; gzip_proxied expired no-cache no-store private auth; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; }