nextjs13,导出静态文件,nginx怎么配置?

output: "export"
image.png
打包出来是这样。我不知道nginx应该怎么配置了。
try_files $uri /index.html;
nginx这样配置,点击路由可以跳转,刷新页面竟然到首页。

nginx 配置

location / {
  # 将以.html结尾的请求添加Cache-Control头信息
  if ($uri ~* \.(html)$) {
      add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
  }

  location ~ ^/([a-zA-Z0-9_-]+)/ {
    try_files $uri /$1.html;
  }
  # 默认情况下,转发到index.html
  try_files $uri /index.html;
}
阅读 3k
1 个回答
location / {
  # 将以.html结尾的请求添加Cache-Control头信息
  if ($uri ~* \.(html)$) {
      add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
  }

  # 默认情况下,根据路径转发,找不到加载index.html
  try_files $uri /$uri.html /index.html;
}

正确的nginx配置文件

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题