Node.js Nginx套接字io websockets代理传递
我一直在想如何在nginx中代理传递套接字io/websocket数据 当尝试套接字io连接时,我在nginx中不断遇到此错误Node.js Nginx套接字io websockets代理传递,node.js,sockets,nginx,proxypass,Node.js,Sockets,Nginx,Proxypass,我一直在想如何在nginx中代理传递套接字io/websocket数据 当尝试套接字io连接时,我在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
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
}
}
在前端,每当socket io尝试轮询时,我都会收到一个404 not found响应,这不是由NGINX生成的
我的连接字符串是:
var socket = io.connect('http://url.com',{'force new connection': true, path: '/io/socket.io'});
服务器似乎与静态路径文件存在某种冲突
我通过将应用程序放在子域上使其正常工作。您是说让socket.io在单独的子域上侦听吗?