Search code examples
node.jsnginxmean-stackpm2

starting node.js app with pm2 : bad gateway from proxy_verse server


on my server1 , I run nginx as reverse_proxy to server2 which is running a node.js app on port 3000 ( full MEAN stack)

when I start server2 with grunt, everything is running fine

-- server2 ---
cd /opt/mean
grunt  # running server.js , MEAN app

as a next learning step, I am trying to use pm2 on server2 to monitor my test web app . I installed pm2 and run

-- server2 ---
cd /opt/mean
pm2 start server.js

and got

        [PM2] restartProcessId process id 0
    [PM2] Process successfully started
    ┌──────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────────────┬──────────┐
    │ App name │ id │ mode │ pid  │ status │ restart │ uptime │ memory      │ watching │
    ├──────────┼────┼──────┼──────┼────────┼─────────┼────────┼─────────────┼──────────┤
    │ server   │ 0  │ fork │ 2182 │ online │ 14      │ 0s     │ 10.867 MB   │ disabled │
    └──────────┴────┴──────┴──────┴────────┴─────────┴────────┴─────────────┴──────────┘
     Use `pm2 show <id|name>` to get more details about an app
    yves@gandalf:/opt/mean$ pm2 show server
    Describing process with id 0 - name server
    ┌───────────────────┬─────────────────────────────────────────┐
    │ status            │ errored                                 │
    │ name              │ server                                  │
    │ id                │ 0                                       │
    │ path              │ /opt/mean/server.js                     │
    │ args              │                                         │
    │ exec cwd          │ /                                       │
    │ error log path    │ /home/yves/.pm2/logs/server-error-0.log │
    │ out log path      │ /home/yves/.pm2/logs/server-out-0.log   │
    │ pid path          │ /home/yves/.pm2/pids/server-0.pid       │
    │ mode              │ fork_mode                               │
    │ node v8 arguments │                                         │
    │ watch & reload    │ ✘                                       │
    │ interpreter       │ node                                    │
    │ restarts          │ 28                                      │
    │ unstable restarts │ 0                                       │
    │ uptime            │ 0                                       │
    │ created at        │ N/A                                     │
    └───────────────────┴─────────────────────────────────────────┘
    Process configuration

    Revision control metadata
    ┌──────────────────┬─────────────────────────────────────────────┐
    │ revision control │ git                                         │
    │ remote url       │ https://github.com/meanjs/mean.git          │
    │ repository root  │ /opt/mean                                   │
    │ last update      │ 2015-09-04T15:02:21.894Z                    │
    │ revision         │ 3890aaedf407151fd6b50d72ad55d5d7566a539b    │
    │ comment          │ Merge pull request #876 from codydaig/0.4.1 │
    │ branch           │ master                                      │
    └──────────────────┴─────────────────────────────────────────────┘

When I try to request my app in the browser , I get now an error from server1

502 Bad Gateway nginx/1.4.6 (Ubuntu)

Do I have to add or update anything into the nginx default config, as the proxy_pass directive is pointing to http://:3000

many thanks for your feedback and Happy New Year 2016 !


Solution

  • That "pm2 show" is showing that your node server errored, so it's probably not running. What do you see if you tail the error log? It should have some details in there about the issue

    The proxy error I think is possibly because node isn't running