Socket.io connects but does not send Emit to the server and vice versa. Nginx and SSL

Asked

Viewed 101 times

1

I am using Nginx with SSL and this setting for a service to communicate with Node, when I access the address the socket.io normally connects with the server but does not receive Emit or send.

location ~ ^/(atualizaUltimaPosicao|node|socket\.io) {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://127.0.0.1:3000;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_set_header Host $host;

        access_log /var/log/nginx/websockets.access.log;
        error_log /var/log/nginx/websockets.error.log

      if ($uri != '/') {
        expires 30d;
      }
   }

This is my Node application, so the user connects it should send Emit but the client does not arrive.

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http, {
  origins: '*:*'
});
http.listen(3000, function() {
  console.log('Listening port 3000');
});
io.on('connection', function(socket) {
  console.log("Client connected");
  socket.emit('posicao', 'test');
  console.log("Sended");
  socket.on('disconnect', function() {
    console.log("Disconected");
  });
});

In the Node application log it sends, Client Connected Sended

Code of the client:

var socket = io.connect('https://mydomain.com.br/atualizaUltimaPosicao');
    if (socket !== undefined || socket !== null) {
        socket.on('posicao', function (data) {
            console.log(data);
    }

I believe it may be some misconfiguration I did on Nginx but I don’t know what it is.

Thanks for the help.

No answers

Browser other questions tagged

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