diff --git a/web-react/nginx.conf b/web-react/nginx.conf index f98b1e3..4245e84 100644 --- a/web-react/nginx.conf +++ b/web-react/nginx.conf @@ -1,20 +1,41 @@ server { listen 80; - # Главное React-приложение - location / { - root /usr/share/nginx/html/app; - try_files $uri /index.html; + root /usr/share/nginx/html/app; + + # Named location — отдаёт React SPA без повторной маршрутизации + 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-билд) - location /editor/ { + location ^~ /editor/ { 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/') - location /editor-assets/ { + location ^~ /editor-assets/ { alias /usr/share/nginx/html/editor/; } @@ -26,6 +47,11 @@ server { proxy_buffering off; } + # Всё остальное — редирект на корень + location / { + return 302 /; + } + gzip on; gzip_types text/plain text/css application/json application/javascript text/xml application/xml; }