Failed to connect to socket.io via nginx

I have nginx configured in such a way that any php request is sent to the Apache server, and any url with /node/

it goes to the node server running on 8888, including the socket listener.

nginx.conf as below

server {
    listen       80;
    server_name   http://domain;

       location / {
                proxy_pass http://localhost:8080;

                }

      location /node {
            rewrite ^/node(.+)$ $1 break;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_pass http://localhost:8888;

            }

        }

      

Now the problem is socket.io request i.e io.connect('domain/node/')

not working with reposnse on the client because "The requested url / socket.io / 1 / was not found on this server", the response is coming from apache !!. But any other node request is sent to the node server as expected. only socket.io request fails.

Also if I run the socket connection url directly as shown in the browser request which looks something like this, domain/node/socket.io/1/?t=1380201512328

works fine and I see the authorization confirmation 8wGgJYUvNdwAdcqenxQd

on the node server.

+1


source to share


1 answer


Try this client side :)

var socket = io.connect (' https: // localhost ', {path: '/node/socket.io'});

I'm also having trouble with this, but you need to provide a path so that the client doesn't send requests for something like this:



GET https://localhost/socket.io/?__sails_io_sdk_version=0.11.0&__sails_io_sdk_p…sails_io_sdk_language=javascript&EIO=3&transport=polling&t=1432066804506-0 504 (Gateway Time-out)

      

Especially since you want it to look like (note the / node ):

GET https://localhost/node/socket.io/?__sails_io_sdk_version=0.11.0&__sails_io_sdk_p…sails_io_sdk_language=javascript&EIO=3&transport=polling&t=1432066804506-0 504 (Gateway Time-out)

      

0


source







All Articles