I'm building an application in PHP + MySQL Database that allows college students to register an account and build up their university schedule for the current semester.
- In page 1, students fill in their personal information
- In page 2, they choose the classes they want to sign-up for
- In page 3, they can see what their schedule will look like based on the classes they chose
I have a HAProxy that balances the requests using roundrobin algorithm to one of my two webservers.
E.g: When client1 connects to my application, his request will be sent to webserver1.
Afterwards, client2 connects to my application, his request will be sent to webserver2.
And so on..
My problem is the way that my HAProxy is switching between webservers, is messing with my users sessions.
Take this for example:
- Client1 connects to application. HAproxy sends his request to Webserver1
- Client1 fills in information, and clicks next
- HAProxy sends request to webserver 2 instead of 1!
And since all the information was passed in webserver 1, webserver 2 won't display any of it!
My question is:
If a client connects to webserver 1, how can I make it so HAProxy forces that client to stay always in webserver 1?
And vice-versa for webserver 2.
This is my HAProxy config file:
Code:
global
log 127.0.0.1 local0
log 127.0.0.1 local0 notice
maxconn 2000
user haproxy
group haproxy
daemon
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
timeout connect 5000
timeout client 10000
timeout server 1000
listen haproxy001 192.168.1.100:80
mode http
stats enable
stats uri /haproxy?stats
stats realm Strictly\ Private
stats auth admin:admin
cookie JSESSIONID prefix
balance roundrobin
option httpclose
option forwardfor
option httpchk HEAD / HTTP/1.0
server server1 192.168.1.93:80 cookie A weight 50 check
server server2 192.168.1.94:80 cookie B weight 50 check