From bb2934fd8ec00edc072ad33878bee02bf53a74da Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Thu, 4 Jun 2026 09:47:30 +0200 Subject: [PATCH] fix(nginx): preserve docs routes and asset 404s --- nginx/nginx.conf | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/nginx/nginx.conf b/nginx/nginx.conf index 4988ea40..7fac3c6f 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -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;