nextjs前端工程如何打包部署(nginx)
把【.next/server/app】目录下的所有文件复制到【/temp/test】文件夹下
把【.next】目录下的所有文件复制到【/temp/text/_next】文件夹下
配置nginx
#配置根目录
location / {
root /temp/test;
index index.html index.htm;
try_files $uri $uri.html $uri/ =404;
}
启动nginx
备注:
1. nextjs打包后会生成多个html,而不是像vue打包后只生成一个html文件
2.前端页面跳转时,路由不包含html后缀,如:http://localhost/login
需要通过nginx的try_files 指令
- 先找原始请求(/about)
- 再自动加.html后缀(/about.html)
- 再找目录(/about/)