简体   繁体   中英

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. 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. 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.

Don't get me wrong, I understand all the features of nginx, having deployed tons of PHP apps with nginx in my days. 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?

Obviously, I am talking about the case of using a single machine for the app, not deploying it to multiple VPSs. 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.

You can use nginx server to serve static content of your application instead of nodejs. As nginx is better at serving static content like html, css, js & image files than nodejs. And another thing is in case of crashing of any node service, you can show proper error pages using nginx.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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