[{"data":1,"prerenderedAt":229},["ShallowReactive",2],{"content:\u002Fposts\u002F2023\u002Fnuxt3-pm2-deploy-nuxt3":3,"surround:\u002Fposts\u002F2023\u002Fnuxt3-pm2-deploy-nuxt3":217},{"id":4,"title":5,"body":6,"canonical":195,"categories":196,"date":198,"description":195,"draft":199,"extension":200,"image":201,"meta":202,"navigation":203,"path":204,"permalink":195,"readingTime":205,"recommend":195,"references":195,"seo":210,"sitemap":211,"stem":212,"tags":213,"type":195,"updated":215,"__hash__":216},"content\u002Fposts\u002F2023\u002Fnuxt3-pm2-deploy-Nuxt3.md","pm2部署Nuxt3",{"type":7,"value":8,"toc":189},"minimark",[9,53,63,71,78,84,92,97,105,108,114,117,123,127,133,136,139,155,162,165,171,183],[10,11,12,36,46],"ol",{},[13,14,15,16,20,21,24,25],"li",{},"使用 ",[17,18,19],"code",{"code":19},"pnpm run build"," 打包，默认会在项目根目录中生成一个 ",[17,22,23],{"code":23},".output"," 文件夹。",[26,27,28],"blockquote",{},[29,30,31,32,35],"p",{},".output 目录包含该项目打包后所需的全部内容，无需像 ",[17,33,34],{"code":34},"Nuxt2"," 将整个文件夹拷贝到对应目录中",[13,37,38,39,41,42,45],{},"将 ",[17,40,23],{"code":23}," 文件上传至服务器中，这里假设为 ",[17,43,44],{"code":44},"portal"," 文件夹中",[13,47,48,49,52],{},"进入对应目录中，配置 ",[17,50,51],{"code":51},"ecosystem.config.js"," 文件",[54,55,61],"pre",{"className":56,"code":58,"language":59,"meta":60},[57],"language-bash","cd portal && touch ecosystem.config.js\n","bash","",[17,62,58],{"__ignoreMap":60},[54,64,69],{"className":65,"code":67,"filename":51,"language":68,"meta":60},[66],"language-js","module.exports = {\n    apps: [\n        {\n            name: \"test-portal\",\n            exec_mode: \"fork\",\n            instances: 1,\n            interpreter: \"\u002Fopt\u002Fhomebrew\u002Fbin\u002Fnode\", \u002F\u002F 这里需要换成服务器中或者本地高版本Node bin目录\n            script: \".output\u002Fserver\u002Findex.mjs\",\n            ignore_watch: [\"node_modules\", \"public\", \"logs\"], \u002F\u002F 不用监听的文件\n            merge_logs: true, \u002F\u002F 设置追加日志而不是新建日志\n            log_date_format: \"YYYY-MM-DD HH:mm:ss\", \u002F\u002F 指定日志文件的时间格式\n            min_uptime: \"60s\", \u002F\u002F 应用运行少于时间被认为是异常启动\n            max_restarts: 30, \u002F\u002F 最大异常重启次数\n            restart_delay: 60, \u002F\u002F 异常重启情况下，延时重启时间\n            env_production: {\n                NODE_ENV: \"production\",\n                PORT: \"3000\",\n            },\n        },\n    ],\n}\n","js",[17,70,67],{"__ignoreMap":60},[29,72,73,74,77],{},"编写 ",[17,75,76],{"code":76},"start-nuxt.sh"," 脚本",[54,79,82],{"className":80,"code":81,"language":59,"meta":60},[57],"touch start-nuxt.sh\n",[17,83,81],{"__ignoreMap":60},[54,85,90],{"className":86,"code":88,"language":89,"meta":60},[87],"language-shell","#!\u002Fbin\u002Fbash\n\necho \"pm2 starting\"\n\npm2 start ecosystem.config.js --env production\n\necho 'pm2 started'\n","shell",[17,91,88],{"__ignoreMap":60},[29,93,94,96],{},[17,95,44],{"code":44}," 目录文件结构",[54,98,103],{"className":99,"code":101,"language":102},[100],"language-text","├── ecosystem.config.js\n├── .output\n└── start-nuxt.sh\n","text",[17,104,101],{"__ignoreMap":60},[29,106,107],{},"启动",[54,109,112],{"className":110,"code":111,"language":59,"meta":60},[57],"sh start-nuxt.sh\n",[17,113,111],{"__ignoreMap":60},[29,115,116],{},"停止服务",[54,118,121],{"className":119,"code":120,"language":59,"meta":60},[57],"pm2 stop test-portal\n",[17,122,120],{"__ignoreMap":60},[124,125,126],"h2",{"id":126},"可能遇到的问题",[29,128,129,130],{},"使用 pm2 部署 Nuxt3 应用时报错 ",[17,131,132],{"code":132},"[nuxt] [request error] [unhandled] [500] The requested module 'vue' does not provide an export named 'unref'",[29,134,135],{},"可能是由于本地 Node 版本过低导致，升级至 18.x 或最新版本即可",[29,137,138],{},"如果本地有多个 node 版本，并使用 nvm 控制版本切换。可以按照下面的步骤进行更改:",[10,140,141,149,152],{},[13,142,143,144,148],{},"可以使用 nvm use ",[145,146,147],"span",{},"node 版本"," 切换 node 版本",[13,150,151],{},"which node 查看当前使用 node 版本的 bin 目录",[13,153,154],{},"修改 ecosystem.config.js 的 interpreter",[29,156,157,158,161],{},"这时，pm2 ",[17,159,160],{"code":160},"exec_mode"," 只能使用 fork 模式，并且只能由单核运行。",[124,163,164],{"id":164},"自动重启策略",[29,166,167,168,170],{},"我的博客托管在我的垃圾云服务器上（特别便宜那种），总是会被不断增加的内存占用占满导致服务器卡死。我们可以在 ",[17,169,51],{"code":51}," 中设置什么时候要自动重启:",[26,172,173],{},[29,174,175,176],{},"可以参考 ",[177,178,182],"a",{"href":179,"rel":180},"https:\u002F\u002Fpm2.keymetrics.io\u002Fdocs\u002Fusage\u002Frestart-strategies\u002F",[181],"nofollow","PM2 Restart Strategies",[54,184,187],{"className":185,"code":186,"filename":51,"language":68,"meta":60},[66],"module.exports = {\n    apps: [\n        {\n            \u002F\u002F ...其他配置\n            restart_time: '0 0 * * *', \u002F\u002F 每天0点重启\n            max_memory_restart: '1G', \u002F\u002F 内存超过 1G 重启\n        },\n    ],\n}\n",[17,188,186],{"__ignoreMap":60},{"title":60,"searchDepth":190,"depth":190,"links":191},4,[192,194],{"id":126,"depth":193,"text":126},2,{"id":164,"depth":193,"text":164},null,[197],"代码","2023-12-05 18:02:30",false,"md","https:\u002F\u002Fbitmc.uno\u002Fpicgo\u002F67a1b5c565c52-78.webp",{},true,"\u002Fposts\u002F2023\u002Fnuxt3-pm2-deploy-nuxt3",{"text":206,"minutes":207,"time":208,"words":209},"3 min read",2.52,151200,504,{"title":5,"description":195},{"loc":204},"posts\u002F2023\u002Fnuxt3-pm2-deploy-Nuxt3",[214],"Nuxt","2025-07-28 11:45:30","fnKor5L5_vifa2Qn6xVGi39rT4eyHHjH6dyBmMl8T3o",[218,224],{"title":219,"path":220,"stem":221,"date":222,"type":223,"children":-1},"再观 ReLIFE 有感","\u002Fposts\u002F2023\u002Freview-relife","posts\u002F2023\u002Freview-ReLIFE","2023-10-21 19:31:18","story",{"title":225,"path":226,"stem":227,"date":228,"type":223,"children":-1},"给未来的一封信——24周岁生日前","\u002Fposts\u002F2023\u002Fa-messy-24","posts\u002F2023\u002FA messy 24","2023-12-17 21:05:11",1789642593237]