nginx vs node-http-proxy
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
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
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.
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.
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
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.