server { listen 80; listen [::]:80; server_name localhost; root /usr/share/nginx/html; index index.html; # HTML: revalidate so content updates are seen quickly location ~* \.html?$ { add_header Cache-Control "public, no-cache"; try_files $uri $uri/ =404; } # Versioned/hashed assets: long cache, immutable location ~* \.(js|css)$ { expires 1y; add_header Cache-Control "public, immutable"; try_files $uri =404; } # Images and media location ~* \.(ico|png|jpg|jpeg|gif|webp|svg|avif)$ { expires 30d; add_header Cache-Control "public"; try_files $uri =404; } # Fonts location ~* \.(woff2?|ttf|otf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; try_files $uri =404; } # Default: serve static files, then try directory/index, then 404 location / { add_header Cache-Control "public, no-cache"; try_files $uri $uri/ /index.html =404; } }