Files
Zimin A.N. b96aad049f fix(docs/nginx): убрать try_files в unhashed fallback — alias bug
nginx с `alias` имеет известный bug: `try_files $uri` резолвит $uri от
document root, не от alias path. Для hashed assets (первое regex location)
try_files уже был убран ранее, но оставался в fallback unhashed location —
из-за этого `/docs/_assets/tabs-extension.js` (и .css) валились в 404
несмотря на наличие файлов в /usr/share/nginx/html/_assets/.

Теперь fallback просто alias'ит без try_files. Если файла нет — nginx сам
отдаст 404 от open() failure (нормальное поведение).
2026-05-08 09:22:15 +03:00

68 lines
2.6 KiB
Nginx Configuration File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Ordinis Integrator Guide — nginx serving static HTML на /docs/.
# Diplodoc генерирует relative links — alias корректно работает без rewrite.
server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name _;
access_log /dev/stdout;
error_log /dev/stderr;
# K8s probe.
location = /healthz {
access_log off;
return 200 "ok\n";
add_header Content-Type text/plain;
}
# Source maps: Diplodoc CLI 4.60 не генерит .map файлы, но оставляет
# `//# sourceMappingURL=` комментарии в JS/CSS. DevTools пытается тянуть.
# 204 No Content триггерит "Unexpected EOF" — DevTools пытается распарсить
# пустое body как JSON sourcemap. Отдаём минимально валидный empty sourcemap.
location ~* "^/docs/.*\.map$" {
access_log off;
log_not_found off;
default_type application/json;
return 200 '{"version":3,"sources":[],"names":[],"mappings":"","file":""}';
}
# Static assets (Diplodoc CLI 4.60 bug: HTML refs hashed names типа
# `_bundle/app-34c68624e23be7ce.css`, но actual файл — `app.css` (без
# hash). Strip hash в nginx через rewrite: `name-<hash>.ext` → `name.ext`.
location ~* "^/docs/(_bundle|_assets)/(.+?)-[a-f0-9]{8,}(\.[a-z0-9]+)$" {
alias /usr/share/nginx/html/$1/$2$3;
expires 1y;
add_header Cache-Control "public, immutable";
}
# Non-hashed assets (fallback). НЕ добавлять `try_files $uri =404` —
# nginx bug: с `alias` $uri резолвится по document root, а не по alias path,
# → ложные 404 на легитимные файлы (tabs-extension.js падает в эту дыру).
# Если файла нет — alias сам отдаст 404 от open() failure.
location ~* ^/docs/((_bundle|_assets)/.*\.(css|js|woff2?|ttf|eot|svg|png|jpg|jpeg|ico|map|json))$ {
alias /usr/share/nginx/html/$1;
expires 1y;
add_header Cache-Control "public, immutable";
}
# Documentation pages (HTML).
location /docs/ {
alias /usr/share/nginx/html/;
index index.html;
try_files $uri $uri/ $uri.html =404;
expires 5m;
add_header Cache-Control "public, must-revalidate";
}
# Redirect /docs (без trailing slash) → /docs/.
location = /docs {
return 301 /docs/;
}
# Security headers.
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
}