Skip to content

nodejs with haproxy

shimondoodkin edited this page Sep 14, 2010 · 24 revisions

Probably i will still use nginx
but add in front of it web sockets
matched by regex or prefix and also, maybe by domain

request goes to haproxy if route match to websocket app1 if otherroute match to websocket app2 else to nginx (nginx routes regular apps)

http://37signals.com/svn/posts/1073-nuts-bolts-haproxy

NOT COMPLETED ARTICLE

i would be glad if some one could do the testing and share the results.
i did some initial research. but i entered to a project and i am kind of little busy.

modifying nginx

make nginx prort to listen on 8089 instead on 80
maybe it is a good idea to consolidate ports.
so maybe to have a file called /var/www/ports.txt with a list of ports used

installing haproxy

aptitude install haproxy
cd /etc/haproxy/
cp haproxy.cfg haproxy.cfg.bak
nano haproxy.cfg

see that:
http://gist.github.com/461583

#
# The trick is to set long timeouts so that the socket connections are not closed.
# Something like:
#
timeout client  86400000 # In the frontend
timeout server  86400000 # In the backend
#
# If you want to serve say a rails and cramp application on the same port 
# you can use ACL rules to detect a websocket connection and use a different backend.
# So your haproxy frontend config would look something like
#
frontend all 0.0.0.0:80
  timeout client    86400000
  default_backend   rails_backend
  acl websocket hdr(Upgrade)    -i WebSocket
  use_backend   cramp_backend   if websocket
#
# For completeness the backend would look like
#
backend cramp_backend
  timeout server  86400000
  server cramp1 localhost:8090 maxconn 200 check
#

http://jkwebdev.wordpress.com/2009/08/29/haproxy-quick-setup/

http://www.pigo.idv.tw/archives/448

http://doc.jeneric.net/index.php/Jeneric_HUB_and_HAProxy

http://www.google.com/search?q=comet+haproxy

http://iamseanmurphy.com/2009/03/02/high-performance-comet-on-a-shoestring/

http://blog.hamzahkhan.com/?p=82

http://rails.nuvvo.com/lesson/3387-nginx-+-haproxy-usage-and-a-gotcha

straight forward link (a comment with high rank, the above is from there , by mloughran):
http://stackoverflow.com/questions/2419346/can-nginx-be-used-as-a-reverse-proxy-for-a-backend-websocket-server

some more links:
http://elwoodicious.com/2008/07/15/nginx-haproxy-thin-fastcgi-php5-load-balanced-rails-with-php-support/

untested:http://yxorp.sourceforge.net/

Clone this wiki locally