server { listen 80; listen [::]:80; server_name _; root /usr/share/nginx/html; index index.html; # React/Vue/Vite SPA routing location / { try_files $uri $uri/ /index.html; } # Do not aggressively cache index.html. # It references the latest hashed JS/CSS files. location = /index.html { try_files $uri =404; add_header Cache-Control "no-cache, must-revalidate"; } # Vite-generated assets normally contain content hashes. # They can safely be cached for a long time. location ~* \.(?:css|js|mjs|map|png|jpg|jpeg|gif|svg|ico|webp|avif|woff|woff2|ttf|otf)$ { try_files $uri =404; expires 30d; add_header Cache-Control "public, max-age=2592000, immutable"; } location = /favicon.ico { access_log off; log_not_found off; } location = /robots.txt { access_log off; log_not_found off; } }