Hi David, For more information about HAProxy and websockets, please have a look at: http://blog.exceliance.fr/2012/11/07/websockets-load-balancing-with-haproxy/
It may give you some hints and point you to the right direction. cheers On Wed, Nov 28, 2012 at 6:34 PM, david rene comba lareu <shadow.of.sou...@gmail.com> wrote: > Thanks willy, i solved it as soon you answer me but i'm still dealing > to the configuration to make it work as i need: > > my last question was this: > http://serverfault.com/questions/451690/haproxy-is-caching-the-forwarding > and i got it working, but for some reason, after the authentication is > made and the some commands are sent, the connection is dropped and a > new connection is made as you can see here: > > info - handshake authorized 2ZqGgU2L5RNksXQRWuhi > debug - setting request GET /socket.io/1/websocket/2ZqGgU2L5RNksXQRWuhi > debug - set heartbeat interval for client 2ZqGgU2L5RNksXQRWuhi > debug - client authorized for > debug - websocket writing 1:: > debug - websocket received data packet > 5:3+::{"name":"ferret","args":["tobi"]} > debug - sending data ack packet > debug - websocket writing 6:::3+["woot"] > info - transport end (socket end) > debug - set close timeout for client 2ZqGgU2L5RNksXQRWuhi > debug - cleared close timeout for client 2ZqGgU2L5RNksXQRWuhi > debug - cleared heartbeat interval for client 2ZqGgU2L5RNksXQRWuhi > debug - discarding transport > debug - client authorized > info - handshake authorized WkHV-B80ejP6MHQTWuhj > debug - setting request GET /socket.io/1/websocket/WkHV-B80ejP6MHQTWuhj > debug - set heartbeat interval for client WkHV-B80ejP6MHQTWuhj > debug - client authorized for > debug - websocket writing 1:: > debug - websocket received data packet > 5:4+::{"name":"ferret","args":["tobi"]} > debug - sending data ack packet > debug - websocket writing 6:::4+["woot"] > info - transport end (socket end) > > i tried several configurations, something like this: > http://stackoverflow.com/questions/4360221/haproxy-websocket-disconnection/ > > and also declaring 2 backends, and using ACL to forward to a backend > that has the > option http-pretend-keepalive > when the request is a websocket request and to a backend that has > http-server-close when the request is only for socket.io static files > or is any other type of request that is not websocket. > > i would clarify that http-server-close is only on the nginx backend > and in the static files backend, http-pretend-keepalive is on frontend > all and in the websocket backend. > > anyone could point me to the right direction? i tried several > combinations and none worked so far :( > > thanks in advance for your time and patience :) > > 2012/11/24 Willy Tarreau <w...@1wt.eu>: >> Hi David, >> >> On Sat, Nov 24, 2012 at 09:26:56AM -0300, david rene comba lareu wrote: >>> Hi everyone, >>> >>> i'm little disappointed with a problem i'm having trying to configure >>> HAproxy in the way i need, so i need a little of help of you guys, >>> that knows a lot more than me about this, as i reviewed all the >>> documentation and tried several things but nothing worked :(. >>> >>> basically, my structure is: >>> >>> HAproxy as frontend, in 80 port -> forwards by default to webserver >>> (in this case is apache, in other machines could be nginx) >>> -> depending the domain >>> and the request, forwards to an Node.js app >>> >>> so i have something like this: >>> >>> global >>> log 127.0.0.1 local0 >>> log 127.0.0.1 local1 notice >>> maxconn 4096 >>> user haproxy >>> group haproxy >>> daemon >>> >>> defaults >>> log global >>> mode http >>> maxconn 2000 >>> contimeout 5000 >>> clitimeout 50000 >>> srvtimeout 50000 >>> >>> >>> frontend all 0.0.0.0:80 >>> timeout client 5000 >>> default_backend www_backend >>> >>> acl is_soio url_dom(host) -i socket.io #if the request contains socket.io >>> >>> acl is_chat hdr_dom(host) -i chaturl #if the request comes from chaturl.com >>> >>> use_backend chat_backend if is_chat is_soio >>> >>> backend www_backend >>> balance roundrobin >>> option forwardfor # This sets X-Forwarded-For >>> timeout server 5000 >>> timeout connect 4000 >>> server server1 localhost:6060 weight 1 maxconn 1024 check #forwards to >>> apache2 >>> >>> backend chat_backend >>> balance roundrobin >>> option forwardfor # This sets X-Forwarded-For >>> timeout queue 50000 >>> timeout server 50000 >>> timeout connect 50000 >>> server server1 localhost:5558 weight 1 maxconn 1024 check #forward to >>> node.js app >>> >>> my application uses socket.io, so anything that match the domain and >>> has socket.io in the request, should forward to the chat_backend. >>> >>> The problem is that if i load directly from the browser, let say, the >>> socket.io file (it will be something like >>> http://www.chaturl.com/socket.io/socket.io.js) loads perfectly, but >>> then when i try to load index.html (as >>> http://www.chaturl.com/index.html) most of the times, is still >>> redirect to socket.io. after refreshing a few time, it finally loads >>> index.html, but then, doesn't load the socket.io.js file inserted in >>> the file (why it redirect to the apache server, and not the node.js >>> app). so as i said, it sort of "caching" the request. >>> >>> i tried several ACL combinations, i disabled the domain check, only >>> checking for socket.io but is still the same. Reading again the >>> documentation i tried to use hdr_dir, hdr_dom, with other headers as >>> URI, url, Request (btw, where i can find a list of headers supported >>> by the layer 7 ACL ?). >>> >>> so, nothing worked, if someone could help me, and point me to the >>> right direction, i would be really grateful :D >> >> You're missing "option http-server-close" in your config, so after >> the first request is done, haproxy switches to tunnel mode and maintains >> the client-server connection without inspecting anything in it. >> >> Regards, >> Willy >> >