Unitech / Unitech/pm2

Second PM2 application is not accessible via HTTP unless HTTP_HOST is set to 0.0.0.0

Open
#4,748 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Inspecting
Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

What's going wrong?

Second Express application is not reachable via HTTP unless the env HTTP_HOST: is set to 0.0.0.0

How could we reproduce this issue?

Start an Ubuntu 16 VM from Digital Ocean
Install node (I use 12.16.3)
Have two Express applications, each with its own ecosystem file following this example present on the server:
apps: [ { exec_mode: 'cluster', instances: 2, output: '/some/path/a.stdout.log', error: '/some/path/a.stderr.log', log: '/some/path/a.combined.log', merge_logs: true, name: 'app1', script: './bin/www', cwd: 'some/path', env: { NODE_ENV: 'development', HTTP_HOST: '127.0.0.1', PORT: 9009, }, }, ], };

  1. Hop onto the VM and start application1 with pm2 start app1-ecosystem.config.js
  2. Open the browser and access VM IP:9009
  3. The express app should be accessible.
  4. With the same ecosystem example, excepting the port, start the second application
  5. Open the browser and access VM IP:9010 (or whatever port was used for the second application)
  6. Observe that when accessing VM IP:9010, the app is not available
  7. In the app2 ecosystem, change the HTTP_HOST env variable to 0.0.0.0 instead of 127.0.0.1
  8. Restart the application (pm2 stop app2 && pm2 delete app2 then run pm2 start app2-ecosystem.config.js
  9. Open the browser and access VM IP:9010 and observe that the application can be access via HTTP

Supporting information

The VM is an Ubuntu 16 from Digital Ocean
Node Version: 12.16.3
Firewall is not enabled
Nginx is not installed (yet)
Both applications can be accessed from within the server with curl.

$ pm2 report

/root/.pm2/pm2.log last 20 lines:
PM2        | 2020-06-16T13:36:16: PM2 log: Stopping app:user-backend id:51
PM2        | 2020-06-16T13:36:16: PM2 log: App name:user-backend id:51 disconnected
PM2        | 2020-06-16T13:36:16: PM2 log: App [user-backend:51] exited with code [0] via signal [SIGINT]
PM2        | 2020-06-16T13:36:16: PM2 log: pid=28221 msg=process killed
PM2        | 2020-06-16T13:36:17: PM2 log: App [user-backend:53] starting in -cluster mode-
PM2        | 2020-06-16T13:36:17: PM2 log: App [user-backend:53] online
PM2        | 2020-06-16T13:36:17: PM2 log: App [user-backend:54] starting in -cluster mode-
PM2        | 2020-06-16T13:36:17: PM2 log: App [user-backend:54] online
PM2        | 2020-06-16T13:36:18: PM2 log: Stopping app:user-backend id:53
PM2        | 2020-06-16T13:36:18: PM2 log: App name:user-backend id:53 disconnected
PM2        | 2020-06-16T13:36:18: PM2 log: App [user-backend:53] exited with code [0] via signal [SIGINT]
PM2        | 2020-06-16T13:36:18: PM2 log: pid=29216 msg=process killed
PM2        | 2020-06-16T13:36:18: PM2 log: App [user-backend:53] starting in -cluster mode-
PM2        | 2020-06-16T13:36:18: PM2 log: App [user-backend:53] online
PM2        | 2020-06-16T13:36:18: PM2 log: Stopping app:user-backend id:54
PM2        | 2020-06-16T13:36:18: PM2 log: App name:user-backend id:54 disconnected
PM2        | 2020-06-16T13:36:18: PM2 log: App [user-backend:54] exited with code [0] via signal [SIGINT]
PM2        | 2020-06-16T13:36:18: PM2 log: pid=29223 msg=process killed
PM2        | 2020-06-16T13:36:18: PM2 log: App [user-backend:54] starting in -cluster mode-
PM2        | 2020-06-16T13:36:18: PM2 log: App [user-backend:54] online

Other notes:
I have not yet tried to run both apps from the same ecosystem file (thing I've done in the past and worked as far as I remember) but due to the fact that multiple projects/apps will be running on the same machine, for easier deployment and configuration I would rather not, at least at the moment.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two-application setup from the ecosystem configuration examples, using the reported Ubuntu, Node.js, cluster mode, ports, and HTTP_HOST values. Compare browser access from outside the VM with curl from inside it, and review the supplied PM2 report. Done means both applications are reachable through their VM IP and configured ports without requiring the second app to use 0.0.0.0.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, nodejs
Domain
backend, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.