2016-02-12 165 views
3

我一直想弄清楚如何在nginx中proxy_pass socket io/websocket數據。Nginx socket io websockets代理通

當我嘗試socket socket連接時,我一直在nginx中收到這個錯誤。

2016/02/12 03:57:42 [info] 1047#0: *15 client closed connection while waiting for request, client: 192.168.1.1, server: 0.0.0.0:4444 
2016/02/12 03:57:42 [info] 1047#0: *13 client closed connection while waiting for request, client: 192.168.1.1, server: 0.0.0.0:4444 
2016/02/12 03:57:42 [info] 1047#0: *14 client closed connection while waiting for request, client: 192.168.1.1, server: 0.0.0.0:4444 
2016/02/12 05:11:19 [info] 1047#0: *18 client closed connection while waiting for request, client: 192.168.1.1, server: 0.0.0.0:4444 
2016/02/12 05:11:19 [info] 1047#0: *20 client closed connection while waiting for request, client: 192.168.1.1, server: 0.0.0.0:4444 
2016/02/12 05:11:19 [info] 1047#0: *22 client closed connection while waiting for request, client: 192.168.1.1, server: 0.0.0.0:4444 
2016/02/12 05:11:19 [info] 1047#0: *24 client closed connection while waiting for request, client: 192.168.1.1, server: 0.0.0.0:4444 

這裏是我的配置:

#inside http block 
upstream socket_nodes { 
    ip_hash; 
    server 127.0.0.1:6969; 
    #socket io app is running on port 6969 
} 

我的服務器塊

server { 
    listen  4444; 

    server_name url.com; 

    #charset koi8-r; 

    location /io/ { 
     proxy_set_header Upgrade $http_upgrade; 
     proxy_set_header Connection "upgrade"; 
     proxy_http_version 1.1; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $host; 
     proxy_pass http://localhost:6969; 
     proxy_buffering off; 
     proxy_buffer_size 8k; 
     proxy_buffers 2048 8k; 
    } 

    location/{ 
     root /path/to/my/static/files/; 
     index index.html index.htm; 
    } 

    location /path/to/http/api/ { 
      proxy_pass http://localhost:2814/; 
      #api app location 
    } 
} 

在前臺,我收到了404未找到響應每次插座IO試圖查詢其不受產生NGINX

我的連接字符串是:

var socket = io.connect('http://url.com',{'force new connection': true, path: '/io/socket.io'}); 

回答

1

看起來,服務器與靜態路徑文件有某些衝突。

我設法通過將應用程序放在一個子域上來實現它。

+0

你是說你讓socket.io在單獨的子域上監聽嗎? – Brightstar