<Proxy balancer://democluster> BalancerMember http://127.0.0.1:8080/demo1 BalancerMember http://127.0.0.1:8080/demo2 status=+H </Proxy>
而我是將訪問 http://127.0.0.1/demo 的請求進行了轉發: php
ProxyPass /demo balancer://democluster ProxyPassReverse /demo balancer://democluster
問題就出在連接後面不一致的path上面了,致使COOKIES沒法共享JSESSIONID
demo1服務器把SESSIONID放在在 /demo1 下面
demo2服務器把SESSIONID放在在 /demo2 下面
所以在訪問demo的請求中,拿不到任何一個保存的在COOKIES裏面的JSESSIONID,因此每次都會分配新的JSESSIONID web
解決辦法一:統一訪問的path和分發的path,都用/demo:
服務器
<Proxy balancer://democluster> BalancerMember http://127.0.0.1:8080/demo BalancerMember http://127.0.0.1:8081/demo status=+H </Proxy>
解決方法二:強制設置反向代理後存放COOKIES的path,使用 負載均衡
ProxyPassReverseCookieDomain locahost www.domain.cn #設置COOKIES的存放域名 ProxyPassReverseCookiePath /demo / #將demo反向代理後的COOKIE統一存放在根目錄
配置到虛擬服務器中: dom
<VirtualHost 127.0.0.1:80> ServerAdmin webmaster@dummy-host.example.com ServerName 127.0.0.1 ProxyPreserveHost On ProxyRequests Off ProxyPass /demo balancer://democluster ProxyPassReverse /demo balancer://democluster ProxyPassReverseCookiePath /demo / ErrorLog "logs/test.localhost-error_log" CustomLog "logs/test.localhost-access_log" common </VirtualHost>