lemooljiang avatar

打包和布署 / nuxt#12

lemooljiang

Published: 12 Aug 2023 › Updated: 12 Aug 2023打包和布署 / nuxt#12

打包和布署 / 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 11id 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:

Written by

Designer , Poet , Technology enthusiasts

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.

More Posts From lemooljiang