nodejs - 我应该如何将 nginx 与 pm2 一起用于以集群模式运行的应用程序? [英] nodejs - How should i use nginx along with pm2 for my application running in cluster mode?

查看:84
本文介绍了nodejs - 我应该如何将 nginx 与 pm2 一起用于以集群模式运行的应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我给了一个在我的应用程序中使用 nginx 和 pm2 的任务.我应该如何在以集群模式使用 pm2 运行的 nodejs 应用程序前面使用 nginx?

I have given a task to use nginx and pm2 in my application. How should i use nginx infront of my nodejs application which is running using pm2 in cluster mode?

还了解到pm2本身自带负载均衡器,那我为什么要用nginx呢?

Also learned that pm2 itself provides built-in load balancer, why should i use nginx then?

推荐答案

如果您使用 Nginx 的唯一原因是负载平衡,那么您可以忽略它.但我必须警告你,与 Nginx 相比,pm2 崩溃更多.

If the only reason you are using Nginx, is to load balance then you can give it a miss. But I must warn you that pm2 breaks down more compared to Nginx.

就我个人而言,我建议您坚持使用 Nginx,它提供诸如提供静态文件、重定向、处理 SSL 证书和开箱即用的错误页面等功能.

Personally, I would suggest you stick to Nginx it provides things like serving static files, doing redirects, handling SSL certificates and serving error pages out of the box.

在 nodejs 前面使用 Nginx 的最简单方法是 代理传递 到 nodejs 正在使用的端口的请求.但在此之前,您可能希望应用更多配置更改.此外,nodejs 几乎可以做 Nginx 可以做的所有事情,但它并不打算这样做.

The simplest way to use Nginx in front of nodejs is to proxy pass the requests to port that is being used by nodejs. But you would probably want to apply some more config changes before you do that. Also, nodejs can do almost everything that Nginx can do, but it was not meant to do that.

查看以下链接:

  1. https://www.quora.com/Should-I-host-a-node-js-project-without-nginx2.Node v0.12.2以来的负载均衡-集群,pm2 或 nginx

这篇关于nodejs - 我应该如何将 nginx 与 pm2 一起用于以集群模式运行的应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆