sticky session with apache web server and tomcat servers

前端 未结 6 557
我在风中等你
我在风中等你 2021-02-01 21:33

I am using apache web server as a load balancer for two tomcat instances behind apache. When the first request goes to node A and second request from the same client goes to no

相关标签:
6条回答
  • 2021-02-01 22:06

    None of the above solutions worked for me, but I found it in MOTECH project documentation here: http://docs.motechproject.org/en/latest/deployment/sticky_session_apache.html

    This config works for me (on Apache 2.4.41):

    <VirtualHost *:80>
        (...)
        Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
        (...)
        <Proxy balancer://mycluster>
            (...)
            BalancerMember http://10.20.30.40:8080 route=backend-1 enablereuse=On
            BalancerMember http://10.20.30.41:8080 route=backend-2 enablereuse=On
    
            ProxySet lbmethod=bytraffic
            ProxySet stickysession=ROUTEID
            (...)
        </Proxy>
    
        ProxyPass / balancer://mycluster/
        ProxyPassReverse / balancer://mycluster/
        (...)
    </VirtualHost>
    
    0 讨论(0)
  • 2021-02-01 22:09

    Pls try this, I'm sure this will work for you.

    Step-1: Add below code in httpd.conf:

    <Proxy balancer://mycluster>
    BalancerMember http://<NODE1>/<APP>/  route=jvm1 
    BalancerMember http://<NODE2>/<APP>/  route=jvm2
    ProxySet lbmethod=bytraffic
    ProxySet stickysession=JSESSIONID
    </Proxy>
    
    ProxyPass /<APP>/ balancer://mycluster/ 
    ProxyPassReverse /<APP>/ balancer://mycluster/
    

    Step-2: Add below code in server.conf:

    a) <NODE1>
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">    
    b) <NODE2>
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm2">
    
    0 讨论(0)
  • 2021-02-01 22:10

    For apache httpd to keep your sessions tied to the same backend, it needs to know which cookie keeps the session ID. For java, this is (usually) JSESSIONID.

    If you're using the ProxyPass directive, use

    ProxyPass /example http://backend.example.com stickysession=JSESSIONID
    

    To be found in the excellent apache httpd documentation.

    0 讨论(0)
  • 2021-02-01 22:29

    This worked for me...

    Instead of using stickysession=JSESSIONID in ProxyPass directive it has to be set within balancer configuration using ProxySet stickysession=JSESSIONID:

    <Proxy balancer://mybalancer>
    BalancerMember ajp://server1:8009 route=tomcat1
    BalancerMember ajp://server2:8009 route=tomcat2
    ProxySet lbmethod=bytraffic
    ProxySet stickysession=JSESSIONID
    </Proxy>
    ProxyPass /myapp/ mybalancer://myapp/
    

    It was not working for me when I was using it in ProxyPass as shown below:

    ProxyPass /myapp/ mybalancer://myapp/ stickysession=JSESSIONID
    

    This should be added to apache docs, because it's such a pain to solve.

    0 讨论(0)
  • 2021-02-01 22:31

    I think your problem is that you are using mybalancer where you have tu use balancer:

    ProxyPass /myapp/ balancer://mybalancer/ stickysession=JSESSIONID
    
    0 讨论(0)
  • 2021-02-01 22:33

    This is a problem I have come across too - if you define your balancer within a vhost then it seems to use the stickysession as documented. However if you are defining a balancer outside of the vhost its used in then the stickysession gets lost so you have to set it using ProxySet within the balancer itself.

    0 讨论(0)
提交回复
热议问题