簡體   English   中英

具有多個進程的PM2配置

[英]PM2 Config with Multiple Processes

我正在嘗試將PM2配置文件配置為在啟動時啟動兩項服務。 我想在8080上的端口80廣告Node api服務器上啟動React。當它運行時,API在80上運行,而8080沒有任何運行。我的文件中缺少什么。 我使用默認的create react設置來創建我的React結構,但不確定腳本應指向哪個文件。 這是我創建的文件:

 module.exports = { apps : [ { name: 'REACTJS', script: 'client/src/index.js', args: "port=80 sitename='React.js Website'", instances: 0, autorestart: true, watch: true, max_memory_restart: '1G', env: { NODE_ENV: 'development' }, env_production: { NODE_ENV: 'production' } }, { name: 'NODEJS', script: 'server/node.js', args: "port=8080 sitename='Node.js API Server'", // Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/ instances: 0, autorestart: true, watch: true, exec_mode: 'cluster' } ] }; 

在您的配置中,您也可以傳遞PORT ,也可以傳遞args ,也可以傳遞ENV [recomended],為此,在您的節點應用程序中,您正在執行以下操作: app.listen(<PORT>) 確保您正在從ENV獲取PORT ,例如: process.env.PORT

在這種情況下,您的配置應如下所示:

//process.js

module.exports={
  apps : [
    {
      name: 'REACTJS',
      script: 'client/src/index.js',
      instances: 1, 
      autorestart: true,
      watch: true,
      max_memory_restart: '1G',
      env: {
        NODE_ENV: 'development',
        port:80,
        sitename:'React.js Website'
      },
      env_production: {
        NODE_ENV: 'production',
        port:80,
        sitename:'React.js Website'
      }
    },
    {
      name: 'NODEJS',
      script: 'server/node.js',
      instances: 1,
      autorestart: true,
      watch: true,
      exec_mode: 'cluster',
      env: {
        NODE_ENV: 'development',
        PORT:8080,
        //... all you ENV vars goes here for development mode
      },
      env_production: {
        NODE_ENV: 'production',
        PORT:8080,
         //... all you ENV vars goes here for production mode
      }
  }
]
};

跑步,

DEV: pm2 start process.js //默認情況下考慮開發模式

PROD: pm2 start process.js --env production

注意:確保在您的節點應用中,您正在從環境中獲取PORT (例如, process.env.PORT

再次在您的React應用中,即client/src/index.js ,請檢查您是否正在使用像process.env.portprocesss.env.PORT這樣的端口號,並相應地更改pm2配置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM