微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Azure 应用服务 (Linux)、NEXT JS 应用、PM2 无法设置集群模式

如何解决Azure 应用服务 (Linux)、NEXT JS 应用、PM2 无法设置集群模式

我已尝试使用启动命令“pm2-runtime start生态系统.config.js”或“pm2 --no-daemon start生态系统.config”在Azure应用服务(Linux)上的Next JS应用程序上通过PM2设置集群.js”。两个命令都失败。当我使用 pm2-runtime 时,传递给 NodeJS 脚本的当前工作目录变为:“wwwroot/ecosystem.config.js/.next”作为“目录参数”并且服务器失败。在第二个命令 pm2 --no-daemon 中,我收到信息未知或意外的选项:--no-daemon。这两个命令都适用于“fork”模式。是否可以使用nextjs应用为azure应用服务设置集群模式?

ecosystem.config.code

module.exports = {
    apps: [
        {
            name: 'next',script: './node_modules/next/dist/bin/next',args: 'start -p ' + (process.env.PORT || 3000),instances: 2,exec_mode: 'cluster',watch: false,autorestart: true,},],};*

--no-daemon 的错误

enter image description here

Error for pm2-runtime
 Error: Could not find a production build in the '/home/site/wwwroot/ecosystem.config.js/.next' directory. Try building your app with 'next build' before starting the production se
rver. https://err.sh/vercel/next.js/production-start-no-build-id
0|next|     at Server.readBuildId (/home/site/wwwroot/node_modules/next/next-server/server/next-server.ts:2044:15)
0|next|     |     at new Server (/home/site/wwwroot/node_modules/next/next-server/server/next-server.ts:199:25)
0|next|     |     at createServer (/home/site/wwwroot/node_modules/next/server/next.ts:41:10)
0|next|     |     at start (/home/site/wwwroot/node_modules/next/server/lib/start-server.ts:9:15)
0|next|     |     at exec (/home/site/wwwroot/node_modules/next/cli/next-start.ts:53:3)
0|next|     |     at /home/site/wwwroot/node_modules/next/bin/next.ts:113:19 code here

解决方法

在 pm2-runtime 之前添加命令 pm2 list 解决了这个问题,我想命令 pm2 list 会初始化 pm2 并为 pm2-runtime 设置正确的路径。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。