server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; # Enable gzip compression gzip on; gzip_vary on; gzip_min_length 1024; gzip_proxied any; gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml+rss image/svg+xml; # 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; add_header Referrer-Policy "strict-origin-when-cross-origin" always; # Handle Next.js static export routes location / { try_files $uri $uri.html $uri/index.html /index.html; } # Cache static assets (Next.js hashed files) location /_next/static/ { add_header Cache-Control "public, max-age=31536000, immutable"; } # Cache other static files location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, max-age=31536000"; } # Custom error pages error_page 404 /404.html; error_page 500 502 503 504 /500.html; }