I have tried to put Eclipse Scout application behind proxy using HAProxy and Docker with two Tomcat containers, but I have some problems. Application is working fine if only one server is active, or both of them. But when active server is shutdown, I am redirected to login screen. Also when only one server is active and second is started I am also redirected to login and session is lost.
What I want to achieve? Distribute traffic to another Tomcat instance if first is overloaded or active Tomcat instance is shutdown. When deploying new version, I would like if possible:
- Shutdown Tomcat1, traffic is redirected to Tomcat2
- Put new .war file and deploy it.
- Turn on Tomcat1
- Shutdown Tomcat2, traffic is redirected to Tomcat1 with new version
- Put new .war and deploy it
- Turn on Tomcat2.
This is my haproxy.cfg:
global
stats socket /var/run/api.sock user haproxy group haproxy mode 660 level admin expose-fd listeners
log stdout format raw local0 info
defaults
mode http
timeout client 10s
timeout connect 5s
timeout server 10s
timeout http-request 10s
log global
frontend stats
bind *:8404
stats enable
stats uri /
stats refresh 10s
frontend myfrontend
bind :80
default_backend webservers
backend webservers
dynamic-cookie-key MYKEY
cookie JSESSIONID prefix nocache
option prefer-last-server
stick-table type string len 36 size 1m expire 8h
stick on cookie(JSESSIONID)
server tomcat1 tomcat1:8080 cookie tomcat1 check
server tomcat2 tomcat2:8080 cookie tomcat2 check
I tried:
- HAProcy configuration without dinamic-cookie-key
- to put JVMRoute to each tomcat instance and naming them tomcat1 and tomcat2
- to add scout.nodeId config property on each myapp.server.war config.properties file naming them tomcat1 and tomcat2
- setting sessionCookiePath in server.xml in each tomcat instance to "/" path.
Every time I get same result. Session invalidated, redirected to /logout.
This is my session in when viewing in developer tools, when tomcat2 is active, session has tomcat2 prefix and suffix: JSESSIONID tomcat1~10AD131758FD28D179111B2261ADD9BF.tomcat1
I am using:
- Scout 11
- Tomcat 8.5.79
- OpenJDK
- HAProxy 2.4
What can I try more to have active session when switching servers? What I am doing wrong?
Thank you!