apache集群,多web应用,粘性会话 不起作用问题的简单解决方法

今天系统部署,发现web应用之间,粘性会话的配置不起作用。因为配置stickysession=JSESSIONID而JSESSIONID生成在各个应用的path下。
在apache中的mod_proxy_balancer.c中:
static char *get_cookie_param(request_rec *r, const char *name)
{
const char *cookies;
const char *start_cookie;

if ((cookies = apr_table_get(r->headers_in, "Cookie"))) {
for (start_cookie = ap_strstr_c(cookies, name); start_cookie;
start_cookie = ap_strstr_c(start_cookie + 1, name)) {
if (start_cookie == cookies ||
start_cookie[-1] == ';' ||
start_cookie[-1] == ',' ||
isspace(start_cookie[-1])) {

start_cookie += strlen(name);
while(*start_cookie && isspace(*start_cookie))
++start_cookie;
if (*start_cookie == '=' && start_cookie[1]) {
/*
* Session cookie was found, get it's value
*/
char *end_cookie, *cookie;
++start_cookie;
cookie = apr_pstrdup(r->pool, start_cookie);
if ((end_cookie = strchr(cookie, ';')) != NULL)
*end_cookie = '\0';
if((end_cookie = strchr(cookie, ',')) != NULL)
*end_cookie = '\0';
return cookie;
}
}
}
}
return NULL;
}

apache没由提供cookie path的设置,因此按照cookie的优先顺序,将首先取到与应用上下文中接近的jsessionid,所以显然,如果各个应用都有同名的sticksession,其值又不同,那么apache粘性会话不能跨web应用。

解决方法也显然有二:
[i]一.修改mod_proxy代码,提供在指定的cookie path读取sticksession的配置
(发现在服务端读不了cookie path,所以此路不同,哈哈)[/i]
二.不使用jsessionid作为stickysession的名字,自己定义一个,并在/添加cookie,如myjsessionid=${your uuid}.server1,其中server1为route id。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值