6

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 e.g., 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.

michnovka
  • 2,880
  • 3
  • 26
  • 58
  • Does this answer answer your question? - https://stackoverflow.com/questions/38821947/node-js-based-server-vs-something-like-the-apache-http-server/38823010#38823010 – slebetman Jun 26 '19 at 01:15
  • @slebetman thanks - sort of. The answer from 2 years ago talks mainly about security and ends with suggesting that nowadays it might not be necessary as node is well tested. Well, do I take the leap of faith? Apache/nginx both had their share of nasty exploits. I would argue that putting another exploitable layer to your network does not increase security but rather weakens it, wouldn't you? As what is there to exploit. If somebody exploits express itself, then reverse proxy solves nothing. same port exposed. and if somebody exploits node.js.. well, the same can happen to nginx – michnovka Jun 26 '19 at 01:21
  • Have you read the Express developer's insight? https://expressjs.com/en/advanced/best-practice-performance.html#use-a-reverse-proxy – le3th4x0rbot Jun 26 '19 at 01:22
  • 1
    It's still about security. I've worked on several projects that runs node as direct front-end server (one of them is a load-balancer written in node replacing nginx). To be honest the tooling around Apache and Nginx is much more mature. There's WAF (web application firewall) plugins etc. ready for you to use. With node you either depend on `npm` modules or your own security savvy. – slebetman Jun 26 '19 at 01:25

1 Answers1

0

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.