nginx vs node-http-proxy

11,686

Solution 1

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.

Solution 2

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.

Share:
11,686

Related videos on Youtube

Erik
Author by

Erik

Updated on September 15, 2022

Comments

  • Erik
    Erik over 1 year

    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
  • srquinn
    srquinn almost 8 years
    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.
  • noderman
    noderman about 7 years
    @srquinn 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.
  • srquinn
    srquinn about 7 years
    @noderman 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.
  • noderman
    noderman about 7 years
    @srquinn -- thanks for the feedback. In fact, the error was between the keyboard and the chair. It was a configuration error on sites-available.