服务器 ubuntu22.04
安装 nodejs
curl -sL https://deb.nodesource.com/setup_18.x | bash -
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install gcc g++ make
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
node --version
npm --version
yarn --version
安装 pm2
$ npm install pm2@latest -g
$ yarn global add pm2
本地打包
使用 pm2 时, 需配置 ecosystem.config.js
- 在项目根目录新建ecosystem.config.js
module.exports = {
apps: [
{
name: 'NuxtAppName',
port: '3000',
exec_mode: 'cluster',
instances: 'max',
script: './.output/server/index.mjs'
}
]
}
打包,上传服务器
yarn build
// 打包后生成 .output 文件夹
// 将 .output 文件夹上传到 服务器