Apache / 使用 JSESSIONID 定义粘性
Apache / Define stickiness with JSESSIONID
我尝试在 Apache 中定义粘性。这是 proxy.conf 中的定义:
<Proxy balancer://fs1>
BalancerMember https://localhost:5006/doc route=node1
BalancerMember https://localhost:5008/doc route=node2
ProxySet stickysession=JSESSIONID|jsessionid
</Proxy>
ProxyPass /doc balancer://fs1
或:
ProxyPass "/doc " "balancer://fs1" stickysession=JSESSIONID|jsessionid scolonpathdelim=On
<Proxy balancer://fs1>
BalancerMember https://localhost:5006/doc route=node1
BalancerMember https://localhost:5008/doc route=node2
</Proxy>
我尝试使用 url 查询参数来实现粘性(因为我知道不建议覆盖 cookie)。正如 Apache 文档中所写:
The second way of implementing stickyness is URL encoding. The web
server searches for a query parameter in the URL of the request. The
name of the parameter is specified again using stickysession. The
value of the parameter is used to lookup a member worker with route
equal to that value. Since it is not easy to extract and manipulate
all URL links contained in responses, generally the work of adding the
parameters to each link is done by the back-end generating the
content. In some cases it might be feasible doing this via the web
server using mod_substitute or mod_sed. This can have negative impact
on performance though.
我在邮递员中发送了 10 次以下请求:
https://{{myserver}}/doc?jsessionid=node1
我注意到请求被传递给 node1
(5 个请求)和 node2
(也是 5 个请求)。但是我定义了stickysession所以它应该选择node1
,每次都去这个节点。
我的目标是客户端将发送请求https://{{myserver}}/doc?jsessionid=nodeX
,请求将传递给nodeX
(不使用cookie..,仅使用粘性是 URL 编码)。
比如客户端发送请求https://{{myserver}}/doc?jsessionid=node1
10次。每 10 次请求将由 https://localhost:5006
.
提供服务
我做错了什么?
经过一番查找,我找到了问题所在。为了通过 URL 请求参数进行路由,您必须包含一个“.”。在 'node1' 之前像这样:
https://{{myserver}}/doc?jsessionid=.node1
这篇博客 post 为我指明了正确的方向:
It is very important that the routes are named by an alphanumeric
prefix, a dot and then a number. Eg: server.1, t.2 etc. The
mod_proxy_balancer code splits this route name using the dot and uses
the second value as the route number. So s.1 would point to “route=1"
http://hkrishnan.in/2013/10/14/debugging-apache-mod_proxy_balancer/
我自己测试过,效果很好!
我尝试在 Apache 中定义粘性。这是 proxy.conf 中的定义:
<Proxy balancer://fs1>
BalancerMember https://localhost:5006/doc route=node1
BalancerMember https://localhost:5008/doc route=node2
ProxySet stickysession=JSESSIONID|jsessionid
</Proxy>
ProxyPass /doc balancer://fs1
或:
ProxyPass "/doc " "balancer://fs1" stickysession=JSESSIONID|jsessionid scolonpathdelim=On
<Proxy balancer://fs1>
BalancerMember https://localhost:5006/doc route=node1
BalancerMember https://localhost:5008/doc route=node2
</Proxy>
我尝试使用 url 查询参数来实现粘性(因为我知道不建议覆盖 cookie)。正如 Apache 文档中所写:
The second way of implementing stickyness is URL encoding. The web server searches for a query parameter in the URL of the request. The name of the parameter is specified again using stickysession. The value of the parameter is used to lookup a member worker with route equal to that value. Since it is not easy to extract and manipulate all URL links contained in responses, generally the work of adding the parameters to each link is done by the back-end generating the content. In some cases it might be feasible doing this via the web server using mod_substitute or mod_sed. This can have negative impact on performance though.
我在邮递员中发送了 10 次以下请求:
https://{{myserver}}/doc?jsessionid=node1
我注意到请求被传递给 node1
(5 个请求)和 node2
(也是 5 个请求)。但是我定义了stickysession所以它应该选择node1
,每次都去这个节点。
我的目标是客户端将发送请求https://{{myserver}}/doc?jsessionid=nodeX
,请求将传递给nodeX
(不使用cookie..,仅使用粘性是 URL 编码)。
比如客户端发送请求https://{{myserver}}/doc?jsessionid=node1
10次。每 10 次请求将由 https://localhost:5006
.
我做错了什么?
经过一番查找,我找到了问题所在。为了通过 URL 请求参数进行路由,您必须包含一个“.”。在 'node1' 之前像这样:
https://{{myserver}}/doc?jsessionid=.node1
这篇博客 post 为我指明了正确的方向:
It is very important that the routes are named by an alphanumeric prefix, a dot and then a number. Eg: server.1, t.2 etc. The mod_proxy_balancer code splits this route name using the dot and uses the second value as the route number. So s.1 would point to “route=1" http://hkrishnan.in/2013/10/14/debugging-apache-mod_proxy_balancer/
我自己测试过,效果很好!