简体   繁体   English

为什么express.js应用几乎总是位于nginx或其他Web服务器之后?

[英]Why is express.js app almost always behind nginx or other web server?

I have seen tons of examples and read tons of articles about nodejs express app deployment. 我看了无数的示例,并阅读了有关nodejs express应用程序部署的大量文章。 Almost always after implementing all logic (including serving static files) in express, the next step is to forget all the claims about how incredibly fast node.js is and how amazing it is in all benchmarks for concurrent requests. 几乎总是在实现所有逻辑(包括提供静态文件)后,下一步就是忘记关于node.js的速度如此之快以及在所有并发请求基准中它的惊人程度的所有主张。 After you no longer remember the reasons why you learnt this amazing new technology which changes the world and how we think of web applications, there you go and install good old nginx to act as an entry gate to your express app. 在您不再记得学习此惊人的新技术(改变世界的方式以及我们对Web应用程序的看法)的原因之后,您便可以安装旧的Nginx作为快速应用程序的入门。

Don't get me wrong, I understand all the features of nginx, having deployed tons of PHP apps with nginx in my days. 不要误会我的意思,我了解nginx的所有功能,并且在我的日子里已经使用nginx部署了大量的PHP应用程序。 But simply put, why? 但简单地说,为什么? Why not let my app be balanced by pm2 eg, run it on all cores of my VPS and have node.js native clustering support handle the load balancing? 为什么不让我的应用程序通过pm2进行平衡,例如,在我的VPS的所有内核上运行它并让node.js本机群集支持处理负载平衡?

Obviously, I am talking about the case of using a single machine for the app, not deploying it to multiple VPSs. 显然,我在谈论的是为应用程序使用一台机器,而不是将其部署到多个VPS的情况。 Then a load balancer of some sort again does make some sense. 然后,某种形式的负载均衡器确实有意义。

Thank you anybody who can explain the reasons for using a web server to forward traffic to another webserver. 谢谢任何可以解释使用Web服务器将流量转发到另一个Web服务器的原因的人。

You can use nginx server to serve static content of your application instead of nodejs. 您可以使用nginx服务器来提供应用程序的静态内容,而不是nodejs。 As nginx is better at serving static content like html, css, js & image files than nodejs. 由于nginx比nodejs更好地提供诸如html,css,js和图像文件之类的静态内容。 And another thing is in case of crashing of any node service, you can show proper error pages using nginx. 另外,万一任何节点服务崩溃,您可以使用nginx显示正确的错误页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM