简体   繁体   English

无法通过Nginx连接到socket.io

[英]Not able to connect to socket.io through nginx

I have nginx configured such that any php request goes to Apache server and any url with /node/ in it goes to the node server running on 8888 including a socket listener. 我已经配置了nginx ,以便任何php请求都可以到达Apache服务器,并且任何带有/node/ URL都可以到达运行在8888上的节点服务器,包括套接字侦听器。

the nginx.conf is as below nginx.conf如下

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 that a socket.io request ie io.connect('domain/node/') fails with the reposnse at client as "The requested URL /socket.io/1/ was not found on this server", response being served from apache!!. 现在的问题是, socket.io request ie io.connect('domain/node/')失败,并在客户端发出请求,因为“在此服务器上未找到所请求的URL /socket.io/1/”从Apache服务!! But any other node request goes to the node server as expected. 但是,任何其他节点请求都会按预期发送到节点服务器。 only the socket.io request fails. 只有socket.io请求失败。

Also if I run the socket connect URL directly as seen in the browser request which looks something like 另外,如果我直接运行套接字连接URL,如浏览器请求中所示,看起来像
domain/node/socket.io/1/?t=1380201512328 works perfectly fine and I can see handshake authorized 8wGgJYUvNdwAdcqenxQd on node server. domain/node/socket.io/1/?t=1380201512328可以正常工作,我可以在节点服务器上看到握手授权的8wGgJYUvNdwAdcqenxQd

Try this on the clientside :) 在客户端上尝试:)

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

I'm having problems with this aswell, but you need to specify path so the client wont send requests to 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 (notice /node ): 特别是因为您希望它看起来像(notice / 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM