Configure Nginx for multiple Socket.IO servers

Asked

Viewed 404 times

1

The idea here is to decentralize, make a load Balancing.

In the following scenario:

.1 a website serving multiple subdomains with Nginx

.2 two or more servers nodejs spinning socket.io

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

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

Officially Socket.IO doesn’t help much and its documentation using-Multiple-nodes and the closest I came to an understanding was through this tutorial deploy-Multiple-Node-js-socket-io-Servers-with-Nginx-and-ssl.

But although the idea is decentralize even so I still need that socket.io or the sockets based on the point of origin in this case a rom specifies.

I read in some reviews that this could be done with Redis however Redis is not an alternative for me because I am using MongoDB then I found this: socket.io-mongodb who does the same thing that he would do with Redis.

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

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

And in the javascript of the 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');
  • Do you want to load even Balancing or just point each subdomain to a nodejs app? You can use Nginx as a proxy for your apps. Hence each Node app will run on a port and you configure Nginx to point the subdomain to the correct port.

  • @George Moura I do not want to proxy to subdominios already I have server Blocks for this, what I want to do is to make a loading Balancing for the requests to sockets Servers because they can be called from any domain you understand?

  • See if this link can help you: https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-load-balancing

  • @Georgemoura the link was of great help was that even balancing the load between multiple sockets. if you can add an answer within the context of my question to stay of reference and for acceptance. grateful

1 answer

0


Browser other questions tagged

You are not signed in. Login or sign up in order to post.