3

I try to scale my socket.io application and try to run several processes on my server.

I use redis store instead of memory store as described here: https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO

My server listens to port 8090: var io = require('/usr/local/lib/node_modules/socket.io').listen(8090);

When I start a second process, I get an address in use error: warn - error raised: Error: listen EADDRINUSE

What's the best way handle this issue? A port for each process and a load balancer to distinguish between them?

Or is there a better solution?

Martin Kapfhammer
  • 260
  • 1
  • 4
  • 18

1 Answers1

6

For this I use node-http-proxy, and route the traffic to internal ports based off of the URL being requested. Below is a very stripped down example of what I am using to route requests.

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

var httpOptions = {
    router: {
        'domain1.com/foo': 'localhost:3001',
        'domain1.com/bar': 'localhost:3002',
        'domain2.com/baz': 'localhost:3003',
    } 
};

var httpServer = httpProxy.createServer(httpOptions);
httpServer.listen(80);

More details on my particular setup can be found on this question: How to use vhosts alongside node-http-proxy?

Community
  • 1
  • 1
Timothy Strimple
  • 22,920
  • 6
  • 69
  • 76