fix(nginx): preserve docs routes and asset 404s

This commit is contained in:
Andras Bacsai
2026-06-04 09:47:30 +02:00
parent 35f961e2cb
commit bb2934fd8e
+30 -5
View File
@@ -25,6 +25,7 @@ http {
listen 80;
server_name _;
absolute_redirect off;
root /usr/share/nginx/html;
# # Static files handling
# location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
@@ -34,18 +35,42 @@ http {
include /etc/nginx/conf.d/redirects.conf;
# Keep missing static assets as real 404s instead of redirecting them to the docs home.
# The generated app emits page files at the web root while public assets are served under /docs.
location ~* ^/docs/(.+\.(?:avif|css|gif|ico|jpe?g|js|json|map|png|svg|ttf|txt|webmanifest|webp|woff2?|xml))$ {
try_files $uri /$1 =404;
}
location ~* \.(?:avif|css|gif|ico|jpe?g|js|json|map|png|svg|ttf|txt|webmanifest|webp|woff2?|xml)$ {
try_files $uri =404;
}
location = /docs {
try_files /docs/index.html /index.html @docs_soft_404;
}
location = /docs/ {
try_files /docs/index.html /index.html @docs_soft_404;
}
location ~ ^/docs/(.+)$ {
index index.html;
try_files $uri/index.html $uri.html $uri /$1/index.html /$1.html /$1 @docs_soft_404;
}
location / {
root /usr/share/nginx/html;
index index.html;
# # Add rewrite rule to handle URLs without trailing slash
# rewrite ^([^.]*[^/])$ $1/ permanent;
try_files $uri/index.html $uri.html $uri =404;
try_files $uri/index.html $uri.html $uri @docs_soft_404;
}
location @docs_soft_404 {
return 302 /docs;
}
# non existent pages are redirected to 404.html
error_page 404 /404.html;
# a folder without index.html raises 403 in this setup
error_page 403 /404.html;
error_page 403 =302 /docs;
location = /favicon.ico {
rewrite ^/favicon.ico$ /docs/brand/favicon.ico;
access_log off;