2014-12-04 54 views
0

在我的发展MACCHINE代理服务器我的nginx作为代理服务器的WebSocket此配置:Nginx的作为不工作sockio.io WebSocket的远程

server { 
    listen  80; 

    location /socket.io { 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    proxy_set_header X-NginX-Proxy true; 
    proxy_set_header Upgrade $http_upgrade; 
    proxy_set_header Connection "upgrade"; 
    proxy_http_version 1.1; 

    proxy_set_header Host $host; 
    proxy_pass http://127.0.0.1:3001; 
    proxy_redirect off; 
    } 

    location/{ 
    proxy_pass http://trunk.alban:81; 
    client_max_body_size 500M; 

    } 
} 

当我通过火狐来自同一MACCHINE访问的WebSockets正确连接并开始交换消息:

[[email protected] nodejs]# node websocket.js 

2014-12-04 10:27:16 ==> Listening on port: 3001 
2014-12-04 10:27:16 ==> Auth token: alyt4qxs9k9k95a7q1if6r3a8b7yzaor 
2014-12-04 10:27:29 ==> Client authorized: alyt4qxs9k9k95a7q1if6r3a8b7yzaor == alyt4qxs9k9k95a7q1if6r3a8b7yzaor 
2014-12-04 10:27:29 ==> IP: [127.0.0.1], URL:[http://trunk.alban], Agent: [Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0] 
2014-12-04 10:27:35 ==> Broadcasting clients: amend-view-status_13 {} 

但是当我从另一个MACCHINE accesss,它连接,但它不发送/接收的任何消息,只是循环的交换协议,连接和disconneting:

2014-12-04 10:32:23 ==> Client authorized: alyt4qxs9k9k95a7q1if6r3a8b7yzaor == alyt4qxs9k9k95a7q1if6r3a8b7yzaor 
2014-12-04 10:32:23 ==> IP: [127.0.0.1], URL:[http://192.168.57.130], Agent: [Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0] 
2014-12-04 10:32:43 ==> Client Disconnected 
2014-12-04 10:32:44 ==> Client authorized: alyt4qxs9k9k95a7q1if6r3a8b7yzaor == alyt4qxs9k9k95a7q1if6r3a8b7yzaor 
2014-12-04 10:32:44 ==> IP: [127.0.0.1], URL:[http://192.168.57.130], Agent: [Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0] 
2014-12-04 10:33:04 ==> Client Disconnected 
2014-12-04 10:33:06 ==> Client authorized: alyt4qxs9k9k95a7q1if6r3a8b7yzaor == alyt4qxs9k9k95a7q1if6r3a8b7yzaor 
2014-12-04 10:33:06 ==> IP: [127.0.0.1], URL:[http://192.168.57.130], Agent: [Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0] 

我有nginx 1.6.2安装和socket.io 1.2.1。

我已禁用所有可能的防火墙。

注意:如果我删除nginx作为代理服务器,只是通过poin到socket.io服务器直接它工作在任何macchine罚款。

NOTE2:强制使用轮询它工作没有问题。似乎是nginx/ws协议的问题...

任何想法?

回答

0

OK我发现这个问题:在客户端我已经设置的传输选项:

this.socket = io.connect(this.adress, {query: 'token='+this.token /* , resource: 'ws/socket.io' */, transports:['websocket', 'polling']}); 

通过将其取出:

this.socket = io.connect(this.adress, {query: 'token='+this.token}); 

它的作品,从任何远程连接!我无法解释为什么,但它的工作原理。

希望这有助于任何其他用户