Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created March 14, 2011 20:15
Show Gist options
  • Select an option

  • Save indexzero/869781 to your computer and use it in GitHub Desktop.

Select an option

Save indexzero/869781 to your computer and use it in GitHub Desktop.
A simple example of how to do round-robin proxying for a single domain
var httpProxy = require('http-proxy');
//
// Addresses to use in the round robin proxy
//
var addresses = [
{
host: 'ws1.0.0.0',
port: 80
},
{
host: 'ws2.0.0.0',
port: 80
}
];
httpProxy.createServer(function (req, res, proxy) {
//
// Get the first location off of the 'queue'.
//
var target = addresses.shift();
//
// Proxy to the specified location
//
// Remark: You may want to do host header checking here
// by looking at req.headers.host.
//
proxy.proxyRequest(req, res, target);
//
// Push the location to the end of the 'queue'.
//
addresses.push(target);
});
@gernotger
Copy link
Copy Markdown

I wrote a little article with the a full example of this
http://gernot-it.blogspot.com/2011/06/simple-loadbalancer-with-nodejs-https.html

@indexzero
Copy link
Copy Markdown
Author

Cool! Consider it Tweeted :)

@dgershman
Copy link
Copy Markdown

Your example doesn't work anymore.

@sch
Copy link
Copy Markdown

sch commented Nov 6, 2019

Updated version in the examples directory

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