How to do Session Transfer from one server to another in Haproxy?

We have a haproxy that load balances two tomcat servers say app1 and app2 . We have set weights for each of these for instance app1 has weights 255 and the other has app2 0. If any case app1 goes down how to transfer the session and connection seamlessly to app2. Is there we can achieve it through haproxy. We are completely new in trying out haproxy. We will attach our haproxy config below kindly guide us

    log local0
    chroot      /var/lib/haproxy
    pidfile     /var/run/
    maxconn     4000
    user        haproxy
    group       haproxy
    stats socket /etc/haproxy/haproxysock level admin
    daemon defaults
    mode        http
    log         global
    option      dontlognull
    option      http-server-close
    option      httplog
    option      redispatch
    timeout connect 10000 
    timeout client 300000
    timeout server 300000
    maxconn     60000
    retries     3
    stats uri /haproxy_stats
    stats realm HAProxy\ Statistics
    stats auth hadmin:unMetric_2012

frontend  main *:5000
    acl is_app      path_beg       -i /static /images /javascript /stylesheets /js
    acl is_app      path_end       -i .jpg .gif .png .css .js
    acl is_app      path_end       -i /app/
    use_backend app             if is_app
    default_backend             app backend static
    balance     roundrobin
    server      static check backend app    option httpchk GET /app
    balance    roundrobin
     reqrep ^([^\ :]*)/app((/?.*)*)    \1/app\2
      cookie uid preserve indirect
     stick-table type string len 40 size 5M expire 60m
    stick store-response set-cookie(sid) table app    stick on cookie(sid) table app
    stick on url_param(sid) table app    server  app1 cookie s1 weight 255 check
    server  app2 cookie s2 weight 0 check

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.