Search code examples
node.jshttp-proxynode-http-proxy

Combining forward and router for node-http-proxy


I'm hosting multiple Node apps on one AWS instance. I've been using apache with virtual hosts but want to only use Node. The node-http-proxy looks like it will do the task but I can't get the forwarding to work with a proxy table.

Here's how proxy table is supposed to work:

var options = {
router: {
    'app1.website.com': 'localhost:7100',
    'app2.website.com': 'localhost:15110'
}
};

var proxyServer = httpProxy.createServer(options).listen(80);

I have app1 and app2 running on the instance and listening to 7100 and 15110 respectively but just using the router option doesn't allow for forwarding.

I can get just one to forward by using:

var options = {
forward: {
    port: 15110,
    host: 'localhost'
}
};

var proxyServer = httpProxy.createServer(15110, 'localhost', options);

Any idea how to get the benefits of both? The documentation says I can pass both 'forward' and 'router' through options but it's not clear how.


Solution

  • Have you tryed 127.0.0.1 instead of localhost? And what did you mean with "doesn't allow fowarding"? What node-http-proxy do is to internally proxy the request, not forward it :)