server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; # Add gzip compression gzip on; gzip_vary on; gzip_proxied any; gzip_comp_level 6; gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml; # Handle Next.js routes and static files location / { try_files $uri $uri.html $uri/ /index.html =404; add_header Cache-Control "no-cache, no-store, must-revalidate"; } # Handle Next.js API routes location /_next/ { alias /usr/share/nginx/html/_next/; expires 365d; add_header Cache-Control "public, no-transform"; } # Handle static files location /static/ { alias /usr/share/nginx/html/static/; expires 365d; add_header Cache-Control "public, no-transform"; } # Error pages error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } }