Configure Nginx for multiple Socket.IO servers

1

The idea here is to decentralize, do a load balancing .

In the following scenario:

.1 a website serving multiple subdomains with Nginx

.2 two or more servers nodejs running socket.io

My need with nodejs is to keep a server for messages and others for example: advertisements, applications, tools.

Most of the channels I searched for answers told me that the business is to keep everything in one o. ? But if there is a fatal error in tools for example it will end up knocking down everything (apps, ads, chat).

Officially Socket.IO does not help much and its documentation using-multiple-nodes and the closest I came to have an understanding was through this tutorial deploy-multiple-node-js-socket-io-servers-with-nginx-and-ssl

But although the idea is decentralized anyway, I still need to have socket.io or sockets based on the point of origin in this case a rom strong> specifies.

I read in some reviews that this could be done with Redis but Redis is not an alternative for me because I'm using MongoDB so I found this: socket.io-mongodb which does the same thing as it would with Redis .

Following this logic any page HTML would need to read javascript of socket.io (regardless of socket server) eg:

<script type="text/javascript" src="//localhost:9000/socket.io/socket.io.js"></script>

And in%% of pages I would have something like:

//para mensagens
var msg = io.connect('//localhost:9000');

// para o servidor de propagandas
var ads = io.connect('//localhost:7001');

// para o servidor de ferramentas
var tool = io.connect('//localhost:8001');
    
asked by anonymous 07.09.2016 / 11:22

1 answer

0

You can use the nginx upstream module and do something like this:

upstream backend { server backend1.example.com; server backend2.example.com; server backend3.example.com; }

and then refer to the server

server { location / { proxy_pass http://backend; } }

For more details see this digital ocean tutorial: link

    
07.09.2016 / 20:51