我正在开发一个使用websocket处理程序的Tornado应用程序。我正在使用Supervisord运行该应用程序的多个实例,但我在负载平衡websocket连接时遇到了问题。
我知道nginx不支持开箱即用的websocket,但我按照这里的说明http://www.letseehere.com/reverse-proxy-web-sockets使用了nginx tcp_proxy模块来反向代理websocket连接。然而,这并不起作用,因为模块不能路由websocket urls (例如:ws://localhost:80/ this )。因此,它不适用于我在Tornado应用程序中定义的URL路由。
从我对web的研究来看,HAProxy似乎是平衡我的websocket连接负载的方法。然而,我很难找到任何合适的指南来设置HAProxy,以实现websocket连接的负载平衡,并能够处理websocket URL路由。
如果你能给我一些详细的指导,我将不胜感激。我也完全对其他解决方案持开放态度。
发布于 2012-06-05 22:30:45
WebSockets不能很好地遍历代理,因为在握手之后,它们没有遵循正常的HTTP行为。
尝试使用WebSocket (wss://)协议(安全WS)。这将使用代理连接应用程序接口,它将隐藏WebSocket协议。
发布于 2012-10-10 23:53:12
我使用https://launchpad.net/txloadbalancer与Tornado websocket处理程序进行负载均衡。它很简单,而且运行良好(我认为)。
发布于 2014-12-07 18:21:19
http nginx (仅限nginx v1.3+)
upstream chatservice {
#multi thread by tornado
server 127.0.0.1:6661;
server 127.0.0.1:6662;
server 127.0.0.1:6663;
server 127.0.0.1:6664;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}虚拟主机
server {
listen 80;
server_name chat.domain.com;
root /home/duchat/www;
index index.html index.htm;
location / {
try_files $uri $uri/ @backend;
}
location @backend {
proxy_pass_header Server;
proxy_set_header X-Real-IP $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_pass http://chatservice;
internal;
}https://stackoverflow.com/questions/10896175
复制相似问题