Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haproxy sticky sessions

I'm trying to use Haproxy 1.6.3 2015/12/25 and sticky sessions. I did everything according to haproxy manual, but, unfortunately, checking client browser I see that cookies aren't being added (the balancer has to return me cookies in the response after the first request but it returns me nothing and works as nothing happened (without cookies)). Everything else perfectly works, but cookies don't. I've attached my haproxy.cfg:

global
  log /dev/haproxy/log local0
  log /dev/haproxy/log local1 notice
  chroot /var/lib/haproxy
  stats socket /run/haproxy/admin.sock mode 660 level admin
  stats timeout 30s
  user haproxy
  group haproxy 
  daemon

defaults
  log global
  mode http
  option httplog
  option dontlognull
  timeout connect 5000ms
  timeout client 50000ms
  timeout server 50000ms

  stats enable
  stats auth user:pass
  stats uri /haproxy_stats

  option httpchk HEAD / HTTP/1.0
  option redispatch

  balance roundrobin

frontend frontend_http
  bind *:80
  option forwardfor
  default_backend backend_http

backend backend_http
  option prefer-last-server
  cookie mycookies insert indirect nocache
  server server1 196.168.0.125:80 check cookie s1
  server server2 196.168.0.126:80 check cookie s2

Also my servers (server1, server2) are deployed on IIS and balancer is deployed on Ubuntu 16.04 LTS

like image 737
Mike Thorlake Avatar asked Dec 08 '25 06:12

Mike Thorlake


1 Answers

change backend configuration :

backend backend_http
option prefer-last-server
cookie mycookies insert indirect nocache
server server1 196.168.0.125:80 check cookie server1
server server2 196.168.0.126:80 check cookie server2

or

backend backend_http
option prefer-last-server
cookie mycookies insert indirect nocache
server s1 196.168.0.125:80 check cookie s1
server s2 196.168.0.126:80 check cookie s2
like image 158
Olivier PALANQUE Avatar answered Dec 10 '25 23:12

Olivier PALANQUE