node.js - 哪种扩展 Nodejs 应用程序的方式更好?

标签 node.js nginx pm2 nginx-reverse-proxy

我还需要跨不同服务器进行扩展。

  1. 仅使用 pm2 就可以实现这一点,因为它只是从主进程中 fork 子进程,并且也共享相同的端口。
  2. 使用像 Nginx 这样的反向代理是水平扩展的出路吗?

最佳答案

您可以选择 PM2 with Nginx .

这是扩展 Node.js 应用程序的最佳方式。

这是更好的解释:

Nginx on the outside, to be the front door. It should handle SSL and be a reverse proxy into pm2. Bonus points for mapping static assets at nginx, and sheilding node from those requests.

Then pm2. It too is a reverse proxy, but very specific to node processes and really more of a process manager than a webserver. Using it is still a great idea. You can spin up N node processes allowing you to take advantage of multiple CPUs, and pm2 will keep them going in case of a crash. You can make graceful restarts as well, updating one instance of your application at a time, with zero downtime.

Pm2 also comes with some handy utilities like built in (freemium) metrics, and a great little web management tool you could expose to show basic stats, and stdout of your processes.

Having both layers, on the same server or split out if needed, gives you a lot of control and performance. The overhead is not at all bad (since each layer is doing what it does best) and is not at all difficult to set up.

关于node.js - 哪种扩展 Nodejs 应用程序的方式更好?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50503405/

相关文章:

node.js - 使用 cURL CLI 的 HTTPS POST 到 NodeJS 服务器

angular - Docker/Angular4/Nginx

http - 通过 Nginx 无限期缓存 HTTP 响应失败

Kubernetes 上的 Docker nginx 反向代理

javascript - Next js 后端默认是多线程的吗?

javascript - 在从异步函数内部调用函数时,是否有任何理由更喜欢 node.js 中函数的异步版本?

node.js - 如何仅在 Node 版本足够旧的情况下才需要包?

pm2 - 当服务器进程被杀死时如何重新启动 PM2 本身?

javascript - JavaScript 中公共(public)字段声明的意义是什么?

Ubuntu 14.04 - 重启后 pm2 启动不启动