赞
踩
前言
基于:操作系统 CentOS 7.6
使用的工具:Xshell7、Xftp7
服务器基础环境:
所需基础环境本篇文章不进行介绍,请自行百度了解、安装。
1.将整个项目上传至服务器
除 .git、.next、node_modules 之外的项目文件上传至服务器
2.安装依赖
npm install
3.项目打包
npm run build
4.使用pm2启动Next.js生产服务器
pm2 start npm --watch --name next.js -- start
pm2 start: 启动命令 npm: 包管理器名称
–name: 进程名称
– start: 对应的是 package.json 中的启动命令(如本地启动为 npm run dev,那么这里的start就替换成dev)
5.查看端口占用情况
netstat -nultp
next 启动后默认端口为3000,可以使用 netstat -nultp 查看端口占用情况
如果需要更改启动端口的话,有两种方法。
第一种(适用于端口固定的情况)
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p 8888",
"lint": "next lint"
}
第二种(适用于启动pm2时定义端口的情况)
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p $PORT",
"lint": "next lint"
}
第二种方式示例:
PORT=8888 pm2 start npm --watch --name next.js -- start
杀死指定进程
kill PID
6.配置nginx.conf
location / {
proxy_pass http://127.0.0.1:3000/;
}
7.效果图
如果本篇文章对你有帮助的话,很高兴能够帮助上你。
当然,如果你觉得文章有什么让你觉得不合理、或者有更简单的实现方法又或者有理解不来的地方,希望你在看到之后能够在评论里指出来,我会在看到之后尽快的回复你。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。