server { listen 80; server_name localhost; root /usr/share/nginx/html; index index.html; # 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/rss+xml application/atom+xml image/svg+xml; # Root redirect: detect browser language, fallback to /en/ location = / { set $locale "en"; if ($http_accept_language ~* "(^|,\s*)ru") { set $locale "ru"; } return 302 /$locale/; } # Cache hashed static assets (JS, CSS, fonts) — matched before locale prefix blocks # root is inherited from server block, so /en/static/js/file.js resolves correctly location ~* \.(js|css|woff|woff2|ttf|eot)$ { expires 1y; add_header Cache-Control "public, immutable"; } # Cache images location ~* \.(png|jpg|jpeg|gif|ico|svg)$ { expires 1y; add_header Cache-Control "public, no-transform"; } # English locale — SPA fallback for non-asset routes location /en/ { try_files $uri $uri/ $uri.html /en/index.html; } # Russian locale — SPA fallback for non-asset routes location /ru/ { try_files $uri $uri/ $uri.html /ru/index.html; } # Error pages error_page 404 /en/index.html; }