Load balancer example (wishlist) #28

Closed
paoloskater opened this Issue Mar 13, 2011 · 4 comments

Projects

None yet

2 participants

@paoloskater

Hi Charlie,
I'm new to node.js (I learned of it... today), and your http-proxy is one of the first apps I found. The approach is new and very interesting.
However, from your explanation, it seems it can also be used as a kind of load balancer (I have 2 web servers, ws1 and ws2, and the http-proxy at hp1 could connect to both).

Is there an example about that? Maybe it's trivial and a I'm missing something. Or this use-case has to be developed from scratch?

Thank you
Paolo

Owner

If you're balancing across servers with multiple hosts (i.e. ws1 runs www.foo.com and ws2 runs www.bar.com) then you can use the ProxyTable features. Just pass in a routes object when you create the HttpProxy instance:

  var httpProxy = require('http-proxy');

  var proxy = httpProxy.createServer({
    router: {
      'foo.com': 'ws1.ws1.ws1.ws1:8000',
      'bar.com': 'ws2.ws2.ws2.ws2:8000'
    }
  });

Hope that helps.

Thank you for the quick feedback!
I've only one service (e.g. www.myservice.com at ws0.ws0.ws0.ws0) and I'd like the load is distributed to 2 "worker" servers (ws1.ws1.ws1.ws1 and ws2.ws2.ws2.ws2). So if a user accesses www.myservice.com and, e.g, ws1 fails or is broken, the balancer sends requests to ws2, and viceversa.
Is it possible with http-proxy?

Owner

Yes, it is possible. I think this is what you want:

https://gist.github.com/869781

Let me know if that works for you.

That was precisely what I was looking for. I'm putting it in the stack and I'll be back with a report.
Thank you!
Paolo

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment