goga goglika
goga goglika

Reputation: 84

how to configure ecosystem.config.js file for next.js on apache

am trying to deploy nextjs app on apache using pm2. I have installed latest versions of node, pm2. and apache is configured as reverse proxy. but when am trying to start daemon process, it is not doing it. I cloned a project from github and ran 'npm run build, which created .next file and in that file, I created ecosystem.config.js file for pm2, it looks like this :

module.exports = {
  apps : [{
    name: "nextjs-app",
    script: "npm",
    args: "run build",
    env: {
      NODE_ENV: "production"
    }
  }]
};

but when I ran pm2 start npm -- start , terminal is giving me respone like this:

pm2 start npm -- start
[PM2] Spawning PM2 daemon with pm2_home=/home/georgianar/.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting /usr/local/bin/npm in fork_mode (1 instance)
[PM2] Done.

but when I try to see list of process, there is none, and when user tries to enter the website, site log shows that there is no service on port 3000


(111)Connection refused: AH00957: http: attempt to connect to 127.0.0.1:3000 (localhost:3000) failed

and

AH01114: HTTP: failed to make connection to backend: localhost

I dont know why, any idea why it is doing so?

Upvotes: 4

Views: 2990

Answers (2)

Yuniac
Yuniac

Reputation: 583

Your ecosystem.config.js file should look like this:


module.exports = {
  apps: [
    {
      name: "your-app-name",
      // path to `next` from `node_modules` (the lack of `./` at the start of the path is on purpose)
      script: "node_modules/next/dist/bin/next",
      args: "start",
      env_production: {
        NODE_ENV: "production",
      },
      // ...other config
    },
  ],
};


Then, run: pm2 startOrReload ecosystem.config.js --env production.

The key takeaway here is that the script value should point to next from node_modules.

Upvotes: 0

Dolph
Dolph

Reputation: 21

You do not need a ecosystem file if you just want to run the already deployed and builded next app in your server with pm2.

Just run from your project root folder:

pm2 start npm --name "app_name" -- start

Upvotes: 0

Related Questions