fix(nginx): add explicit root and fix regex location priority for static assets
Regex locations (~* .js|css|woff2 etc) have higher priority than prefix locations (/en/, /ru/) in nginx. Without an explicit root in the server block, the caching location had no root to serve files from, causing 404s for all /en/static/... and /ru/static/... assets. - Add root /usr/share/nginx/html to server block so all locations inherit it - Remove alias from /en/ and /ru/ locations (redundant with explicit root) - Reorder: caching regex locations before locale prefix locations (documents intent) Made-with: Cursor
This commit is contained in:
1 parent
cd40139eea
commit
bed091a14f
1 file changed
+15
-15
@@ -2,6 +2,9 @@ server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Gzip compression
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
@@ -18,21 +21,8 @@ server {
|
||||
return 302 /$locale/;
|
||||
}
|
||||
|
||||
# English locale
|
||||
location /en/ {
|
||||
alias /usr/share/nginx/html/en/;
|
||||
index index.html;
|
||||
try_files $uri $uri/ $uri.html /en/index.html;
|
||||
}
|
||||
|
||||
# Russian locale
|
||||
location /ru/ {
|
||||
alias /usr/share/nginx/html/ru/;
|
||||
index index.html;
|
||||
try_files $uri $uri/ $uri.html /ru/index.html;
|
||||
}
|
||||
|
||||
# Cache hashed static assets (JS, CSS, fonts)
|
||||
# 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";
|
||||
@@ -44,6 +34,16 @@ server {
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user