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.
This commit is contained in:
@@ -198,11 +198,12 @@ http {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Next.js 静态导出的页面路由 + ISR/SSR 回源
|
# Next.js 静态导出的页面路由 + ISR/SSR 回源
|
||||||
# 1) 优先命中已构建的静态 HTML/资源
|
# 1) 优先命中已构建的静态 HTML/资源(含目录 index.html)
|
||||||
# 2) 未命中时转交给 Next.js 运行时(ISR 首次渲染、Draft 预览、动态路由)
|
# 2) 未命中时转交给 Next.js 运行时(ISR 首次渲染、Draft 预览、动态路由)
|
||||||
|
# 注意:不能用 $uri/ 兜底目录,否则根路径会因目录无 index.html 直接 403 而不是回源
|
||||||
location / {
|
location / {
|
||||||
limit_req zone=general burst=20 nodelay;
|
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
|
# ISR/SSR 回源 named location
|
||||||
|
|||||||
Reference in New Issue
Block a user