Published: 12 Aug 2023 › Updated: 12 Aug 2023

打包和布署 / nuxt#12
当一切都开发好后,就是打包和布署啰,开发体验还是很好的:轮子都造好了,放在了顺手的位置。这大概也是不少Vue的开发者转向Nuxt的原因吧。
更改服务器端口
1. yarn build , 得到, .output/server/index.mjs
2. 设置服务器端口 port
源码: .output\server\chunks\nitro\node-server.mjs
//const port = destr(process.env.NITRO_PORT || process.env.PORT) || 3e3;
const port = 9866
3. `node server/index.mjs`, 即可运行
更改服务器端口这项查看了挺久的文档,也没发现配置在哪,只能选择最直接的办法:在源码中修改,好在还算简单。
pm2
npm install -g pm2
pm2 -v // 5.3.0
//启动应用
pm2 start app.js --name my-api # Name process
pm2 start app.js
// 列出 PM2 管理的所有应用程序的状态:
$ pm2 [list|ls|status]
// 查看实时日志:
$ pm2 logs
查看监控信息
$ pm2 monit
// 启动 express 应用
$ pm2 start -n demo ./bin/www
// 启动 nuxt.js 应用
项目根目录创建 ecosystem.config.js 配置:
module.exports = {
apps: [
{
name: 'ProjectName',
script: './node_modules/nuxt/bin/nuxt.js',
args: 'start -e production'// pm2执行其实就是 `nuxt start -e production`
}
]
}
//停止、删除进程
pm2 stop/delete 11:停止/删除id为 11 的进程;
pm2 stop/delete all:停止/删除所有进程;
//日志操作
pm2 logs:显示所有进程的日志;
pm2 logs 11:显示进程id为 11 的日志;
pm2 flush:清空所有日志文件;
pm2 reloadLogs:重载所有日志;
pm2 startup:产生 init 脚本,保持进程活着;
// 启动项目
pm2 start server/index.mjs --name aijoe
pm2 stop 0 1 //id
pm2 start 0 1
安装上pm2,然后一条命令:pm2 start server/index.mjs --name aijoe 就可以了!
如果还需要安装https证书,那就还要安装nginx,做反向代理,再使用certbot安装ssl证书,就可以搞定了。步骤不少,需要一步步磨练和体会。
Leave 打包和布署 / nuxt#12 to:
Read more #cn posts
Best Posts From lemooljiang
We have not curated any of lemooljiang's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.