From 0b4dff0d373387b9731a1339d71888dcbeecc76a Mon Sep 17 00:00:00 2001 From: zhangxiang Date: Tue, 18 Aug 2026 12:53:43 +0800 Subject: [PATCH] fix(nginx): fall through to Next.js for root path instead of 403 try_files with $uri/ causes Nginx to treat / as a directory and return 403 when no index.html exists in dist root. Use $uri/index.html so static directory indexes still work while unmatched routes (including /) fall through to the Next.js runtime. --- nginx-static-production.conf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nginx-static-production.conf b/nginx-static-production.conf index 25551a8..80586f4 100644 --- a/nginx-static-production.conf +++ b/nginx-static-production.conf @@ -198,11 +198,12 @@ http { } # Next.js 静态导出的页面路由 + ISR/SSR 回源 - # 1) 优先命中已构建的静态 HTML/资源 + # 1) 优先命中已构建的静态 HTML/资源(含目录 index.html) # 2) 未命中时转交给 Next.js 运行时(ISR 首次渲染、Draft 预览、动态路由) + # 注意:不能用 $uri/ 兜底目录,否则根路径会因目录无 index.html 直接 403 而不是回源 location / { limit_req zone=general burst=20 nodelay; - try_files $uri $uri.html $uri/ @nextjs; + try_files $uri $uri.html $uri/index.html @nextjs; } # ISR/SSR 回源 named location