2014-12-04 21 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}); 

它的作品,從任何遠程連接!我無法解釋爲什麼,但它的工作原理。

希望這有助於任何其他用戶