Nginx负载平衡器websocket问题
我是NGINX和WebSocket系统的新手,但根据我的项目要求,我需要检查一些复杂的事情才能完成 我尝试使用NGINX创建一个示例,它使用相同的Url(负载平衡器Url)处理我的WebSocket(端口:1234)和HTTP请求(端口:80) 我使用了三台NGINX服务器,一台作为负载平衡器(10.0.0.163),另外两台作为我的应用服务器,在那里我分别安装了真正的api、10.0.0.152和10.0.0.154。现在,我已经在我的应用服务器上配置了WebSocket 根据上述配置,我的所有请求都将通过10.0.0.163(负载平衡器),其代理设置将请求(HTTP/WebSocket)传递到我的应用服务器(10.0.0.152/154) 注意:每个应用服务器都包含单独的Nginx、php和websocket 这里是10.0.0.154服务器的默认(位置:/etc/nginx/sites available/)文件,该服务器处理同一域上的WebSocket和HTTP请求Nginx负载平衡器websocket问题,nginx,websocket,load-balancing,Nginx,Websocket,Load Balancing,我是NGINX和WebSocket系统的新手,但根据我的项目要求,我需要检查一些复杂的事情才能完成 我尝试使用NGINX创建一个示例,它使用相同的Url(负载平衡器Url)处理我的WebSocket(端口:1234)和HTTP请求(端口:80) 我使用了三台NGINX服务器,一台作为负载平衡器(10.0.0.163),另外两台作为我的应用服务器,在那里我分别安装了真正的api、10.0.0.152和10.0.0.154。现在,我已经在我的应用服务器上配置了WebSocket 根据上述配置,我的所
server{
listen 80;
charset UTF-8;
root /var/www;
index index.html index.htm index.php
server_name localhost 10.0.0.154 ;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
location / {
try_files $uri $uri/ @proxy; autoindex on;
}
location @proxy{
proxy_pass http://wb1;
}
location =/ {
proxy_pass http://wb;
proxy_http_version 1.1;
proxy_buffers 8 16k;
proxy_buffer_size 32k;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Referer $http_referer;
proxy_redirect off;
}
}
以下是10.0.0.163中负载平衡器的默认文件(位置:/etc/nginx/sites available/)
upstream wb{
server 10.0.0.154;
server 10.0.0.152;
}
server{
listen 80;
charset UTF-8;
root /var/www;
index index.html index.htm index.php
server_name 10.0.0.163 ;
location / {
try_files $uri $uri/ @proxy; autoindex on;
}
location @proxy{
proxy_pass http://wb;
}
location =/ {
proxy_pass http://wb;
proxy_http_version 1.1;
proxy_buffers 8 16k;
proxy_buffer_size 32k;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Referer $http_referer;
proxy_redirect off;
}
}
我发现,负载平衡器对于HTTP请求工作正常,但它无法将我的WebSocket请求继续发送到我的应用服务器
我不知道我错过了什么。。如果你们能帮我的话,我会非常感谢你们的配置。我认为您应该检查您的负载平衡器&您的应用服务器配置或版本。这可能是不兼容的问题 您使用的是什么版本的nginx?@VBart我使用的是nginx-1.4.1版本。@VBart--调试代码后,我建立了连接并在30秒后断开连接。我收到错误“Peer not Response.”看起来您尚未配置超时:和。错误日志中有什么?@VBart--谢谢您的回复。我们尝试了代理读取超时,但无效。用户将websocket连接发送到LB(负载平衡器)服务器。LB向node.js(websocket)程序发送数据到应用服务器。Websocket也会握手,但无法通过LB向用户发送帧。您的右@sanjay。。。我检查了LB和应用程序的两个版本。我解决了这个问题。@Rizvan解决方案是什么?版本与loadbalancer nginx和应用程序nginx不匹配。