【发布时间】:2016-05-23 01:42:33
【问题描述】:
我一直在试图弄清楚如何在 nginx 中 proxy_pass 套接字 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 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
}
}
在前端,每次套接字 io 尝试轮询不是由 NGINX 生成时,我都会收到 404 not found 响应
我的连接字符串是:
var socket = io.connect('http://url.com',{'force new connection': true, path: '/io/socket.io'});
【问题讨论】:
标签: node.js sockets nginx proxypass