Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 462
Erik Avatar asked Nov 09 '12 13:11

Erik


People also ask

Is Nginx faster than node?

Node. js is a JS runtime environment that is also an HTTP server with some event-driven features and has many drawbacks in terms of concurrency and high load or user requests to handle a large number of users concurrently. Nginx has the best performance in this case, and it provides the best performance.

Why we use Nginx as a proxy server?

The benefits of using Nginx as a reverse proxy include: Clients access all backend resources through a single web address. The reverse proxy can serve static content, which reduces the load on application servers such as Express, Tomcat or WebSphere.

Why do we need Nginx with node?

This is the core use case of Nginx in Node. js applications. Stateless load balancing — This improves performance while reducing load on backend services by sending off client requests to be fulfilled by any server with access to the requested file. Cache static contents — Serving static content in a Node.

What is difference between Nginx and NodeJS?

Basic Understanding. NginX, is a web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache. Node. js is a Javascript run-time environment that runs on the Chrome V8 Engine.


2 Answers

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.

like image 55
srquinn Avatar answered Oct 19 '22 19:10

srquinn


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.

like image 44
Ben P.P. Tung Avatar answered Oct 19 '22 19:10

Ben P.P. Tung