无法通过Nginx连接到socket.io [英] Not able to connect to socket.io through nginx

查看:516
本文介绍了无法通过Nginx连接到socket.io的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经配置了 nginx ,以便任何php请求都将发送到Apache服务器,并且其中带有/node/的任何URL都将发送到在 8888 上运行的节点服务器,包括套接字听众.

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.conf如下

the nginx.conf is 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;

            }

        }

现在的问题是,socket.io request i.e io.connect('domain/node/')失败,客户端上的回执为在此服务器上未找到请求的URL/socket.io/1/",响应是由apache提供的!! 但是,任何其他节点请求都会按预期发送到节点服务器. 仅socket.io请求失败.

Now the problem is that a socket.io request i.e 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!!. But any other node request goes to the node server as expected. only the socket.io request fails.

另外,如果我直接运行套接字连接URL,如浏览器请求中所示,它类似于
domain/node/socket.io/1/?t=1380201512328 工作正常,我可以在节点服务器上看到握手授权的8wGgJYUvNdwAdcqenxQd.

Also if I run the socket connect URL directly as seen in the browser request which looks something like
domain/node/socket.io/1/?t=1380201512328 works perfectly fine and I can see handshake authorized 8wGgJYUvNdwAdcqenxQd on node server.

推荐答案

在客户端尝试此方法:)

Try this on the clientside :)

var socket = io.connect(' https://localhost ',{路径:'/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)

特别是因为您希望它看起来像(注意/node ):

Especially since you want it to look like (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)

这篇关于无法通过Nginx连接到socket.io的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆