我试图在端口80上运行Web服务器和WebSocket的服务器要使用这个配置做到这一点我使用HAProxy的路由连接:的WebSockets,EM-的WebSocket和HAProxy的502错误
global
maxconn 4096 # Total Max Connections. This is dependent on ulimit
nbproc 1
ulimit-n 65536
defaults
mode http
frontend all 0.0.0.0:80
timeout client 86400000
acl is_websocket hdr_beg(host) -i live
acl is_websocket hdr(Upgrade) -i WebSocket
default_backend www_backend
use_backend production_socket_backend if is_websocket
backend www_backend
balance roundrobin
option forwardfor # This sets X-Forwarded-For
timeout server 30000
timeout connect 4000
server appserver 127.0.0.1:81 weight 1 maxconn 1024
backend production_socket_backend
balance roundrobin
option forwardfor # This sets X-Forwarded-For
timeout queue 5000
timeout server 86400000
timeout connect 86400000
server appserver 127.0.0.1:8083 weight 1 maxconn 1024
我正在使用Google Chrome进行测试。在一些机器我正常连接,别人就会给我一个502错误和EM-WebSocket的日志这样的错误:如果我停止运行代理
#<EventMachine::WebSocket::HandshakeError: Connection and Upgrade headers required>
,并运行在端口80上的web套接字服务器能正常工作,其对我来说,问题出在代理上。我已经读过HAProxy不应该在http模式下运行时处理websockets,因为升级数据包不是有效的HTTP,这可能与我看到的问题有关吗?
Thanks @ v1rtual。我不知道平衡源。不幸的是,我试图在端口80上运行Web服务器和Web套接字服务器,希望Web套接字不会被严格的防火墙阻止。 – Mike
ok,那么你必须将端口80前端更改为tcp模式,以便em-websocket正常工作。您的hdr检查将不再起作用。 socket.io似乎在http模式下工作:http://stackoverflow.com/questions/4360221/haproxy-websocket-disconnection – v1rtual