feat: редирект неизвестных маршрутов на корень /

nginx: любой путь кроме /admin, /editor/, /api/ редиректит на /.
Использован named location @spa чтобы избежать повторной маршрутизации
при внутреннем редиректе try_files → /index.html.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jze9
2026-05-20 19:42:47 +05:00
parent 615c819e97
commit 955f46c9ca

View File

@@ -1,20 +1,41 @@
server { server {
listen 80; listen 80;
# Главное React-приложение root /usr/share/nginx/html/app;
location / {
root /usr/share/nginx/html/app; # Named location — отдаёт React SPA без повторной маршрутизации
try_files $uri /index.html; location @spa {
try_files /index.html =404;
}
# Корневая страница
location = / {
try_files /index.html =404;
}
# Статические ассеты приложения (JS, CSS, шрифты, картинки)
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|json|map)$ {
try_files $uri =404;
}
# Админ-панель — React SPA, все вложенные пути разрешены
location ^~ /admin {
try_files $uri @spa;
} }
# Редактор статей (отдельный React-билд) # Редактор статей (отдельный React-билд)
location /editor/ { location ^~ /editor/ {
root /usr/share/nginx/html; root /usr/share/nginx/html;
try_files $uri /editor/index.html; try_files $uri @editor_spa;
}
location @editor_spa {
root /usr/share/nginx/html;
try_files /editor/index.html =404;
} }
# Статические ассеты редактора (Vite base: '/editor-assets/') # Статические ассеты редактора (Vite base: '/editor-assets/')
location /editor-assets/ { location ^~ /editor-assets/ {
alias /usr/share/nginx/html/editor/; alias /usr/share/nginx/html/editor/;
} }
@@ -26,6 +47,11 @@ server {
proxy_buffering off; proxy_buffering off;
} }
# Всё остальное — редирект на корень
location / {
return 302 /;
}
gzip on; gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml; gzip_types text/plain text/css application/json application/javascript text/xml application/xml;
} }