在特定端口并使用群集模式运行pm2

时间:2020-03-03 12:14:45

标签: nuxt.js pm2

我现在有nuxt js应用程序,它以fork模式运行。

我尝试使用此生态系统文件,但无法正常工作。

module.exports = {
    apps : [{
        name      : 'MyAppName', // App name that shows in `pm2 ls`
        exec_mode : 'cluster', // enables clustering
        instances : 'max', // or an integer
        port: 1234,
        script    : './node_modules/nuxt/bin/nuxt-start', // The magic key
    }]
};

是否可以在特定端口上使用群集模式运行pm2?

1 个答案:

答案 0 :(得分:0)

将pm2的文档与Nuxt.js结合起来,似乎将env变量添加到生态系统文件中应该可以满足您的要求:

apps : [{
        name      : 'MyAppName', // App name that shows in `pm2 ls`
        exec_mode : 'cluster', // enables clustering
        instances : 'max', // or an integer
        env: {
          NUXT_PORT: "1234"
        },
        env_production: {
          NUXT_PORT: "1234"
        },
        script    : './node_modules/nuxt/bin/nuxt-start', // The magic key
    }]

https://nuxtjs.org/faq/host-port/#with-nuxt_host-and-nuxt_port-env-variables

https://pm2.keymetrics.io/docs/usage/application-declaration/#generate-configuration