# Single Page Application Configuration # For React, Vue, Angular apps with client-side routing server { listen 80; listen [::]:80; server_name app.example.com; root /var/www/app/dist; index index.html; # Try file, then directory, then fallback to index.html for client-side routing location / { try_files $uri $uri/ /index.html; } # Cache static assets aggressively (hashed filenames) location ~* \.(js|css|png|jpg|jpeg|gif|svg|ico|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; access_log off; } # Don't cache index.html (app entrypoint) location = /index.html { add_header Cache-Control "no-cache, must-revalidate"; expires 0; } # Gzip compression for text assets gzip on; gzip_vary on; gzip_min_length 1024; gzip_comp_level 6; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript; # 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; # Deny access to source maps in production (optional) location ~ \.map$ { deny all; access_log off; log_not_found off; } }