nginx vs node-http-proxy
Asked Answered
D

2

17

Tell me please what is preferable to use for deployment of nodejs applications nginx or node-http-proxy. What is most robust?

The basic features I need are

  • proxy all requests to non 80 post
  • load balancer
  • Websocket supporting
Daryl answered 9/11, 2012 at 13:56 Comment(2)
IMHO I'd use nginx as a round-robin load balancer and nodeJS nodes behind, but this might be bad design as it strongly bounds with your architecture.Neveda
@BagosGiAr Nginx doesn't support websockets yet, so that doesn't work for his use caseRunning
R
36

Here is a great article on the subject http://www.exratione.com/2012/07/proxying-websocket-traffic-for-nodejs-the-present-state-of-play/

Personally I have played with a lot of configurations in this realm and it all comes down to what you need and where you need to deploy. If you are on your own hardware (or cloud slice, etc.) and you only need to support Node, then node-http-proxy on port 80 is very powerful, robust and allows you to take advantage of technologies like websockets and ssl with little headache.

However, if you have other sites you need to support, say a Drupal or Grails site, facing Nginx on 80 is more standard practice. With that said, there is no reason Nginx can't mount to port 8080 with node-http-proxy on 80 and proxy traffic according to the needed CGI language. This is my preferred configuration and what I currently run in production. I'm very pleased so far. Its fast, robust and I can still support my clients building sites in RapidWeaver along side my own nodejs apps that use websockets and ssl.

Oh and load balancing with node-http-proxy is a piece of cake... check out this simple Round-Robin example https://github.com/nodejitsu/node-http-proxy/blob/master/examples/balancer/simple-balancer.js

Edit:

I've discovered that running node-http-proxy on port 80 is bad practice because it requires the root user to execute node. Instead, use IP tables to reroute port 80 to a non-privileged port where your node-http-proxy is running. Even better setup would be to put varnish on 80 (because as the article says, any serious web app should have an HTTP accelerator in front of it) and forward the requests to node-http-proxy on an unprivileged port. From here, its up to you how you want to split up traffic between your node servers and nginx.

Second Edit:

Nginx now supports websockets! And while the current state of node is quite capable of delivering a full stack, it doesn't mean it should. I mean, technically you could use the handle of a screwdriver to pound a nail into the wall... but why would you if you have a hammer sitting right there? From serving statics to complex load balancing, Nginx is battle tested and deployed in some of the most advanced networks. Its a no brainer now that websocket support has been added.

Running answered 9/11, 2012 at 15:4 Comment(0)
P
4

I was forced to use node-http-proxy in production due to we have to bypass China Internet wall, IMHO, it is quite robust, flexible.

Recently, I am considering to use it more in other fields, so I google and get the following test on

https://github.com/observing/balancerbattle

Based on the test, it seems node-http-proxy is the slowest. However, I think the performance difference is not much, and it also proves that node-http-proxy is robust too. While using node-http-proxy, I can purely use nodejs and build an environment with just few packages.( we use FreeBSD, and I hate to build a lot of packages, which we never need.)

In using node-http-proxy, you are writing your own proxy server, so you can customize the logic as more as you can. It is really unnecessary to use nginx or haproxy for that tiny better performance.

Pained answered 30/12, 2014 at 18:5 Comment(4)
At scale, there are SERIOUS advantages to nginx over node-http-proxy especially since node executes on a single process. I question the validity of the benchmarks in the article you quote because the company has an obvious nodejs bend. Nginx is proven to scale (Amazon, Microsoft, and Google all use it in their IaaS offerings as a load balancer) and JustWorks™ vs building and maintaining a complicated Nodejs proxy.Running
@Running I am desperately trying to make NGINX work with socket.io and Sails.js, but no success. I wonder if NGINX REALLY has support for websockets.Cornie
@Cornie nginx.com/blog/websocket-nginx — I suspect you either have an older version of nginx deployed that doesn't support websockets (< v1.3.13) or you've got a misconfiguration. Update nginx or post a new question to the community re: your specific issue.Running
@Running -- thanks for the feedback. In fact, the error was between the keyboard and the chair. It was a configuration error on sites-available.Cornie

© 2022 - 2024 — McMap. All rights reserved.