diff --git a/docker/nginx.conf b/docker/nginx.conf index 04e9641..0134bc9 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -5,6 +5,20 @@ server { root /usr/share/nginx/html; index index.html; + # VitePress 配置 base: '/docs/',构建产物里的资源引用是绝对路径 /docs/assets/xxx, + # 而 dist 目录是平铺的(index.html、assets/ 直接在根)。 + # 因此必须在 /docs/ 路径下提供服务,用 alias 把前缀剥掉再落到产物目录, + # 否则页面能返回 200 但 JS/CSS 全部 404 → 白屏。 + location /docs/ { + alias /usr/share/nginx/html/; + try_files $uri $uri.html $uri/ $uri/index.html =404; + } + + # 根路径跳到文档入口,避免访问 / 时白屏 + location = / { + return 302 /docs/; + } + location / { try_files $uri $uri.html $uri/ =404; }