通过sessionid转发web请求
1--安装nginx-0.7.65
1-0下载包
jvm-route安装包下载命令:
svn checkout http://nginx-upstream-jvm-route.googlecode.com/svn/trunk/ nginx-upstream-jvm-route-read-onlynginx当前稳定版下载路径wget http://nginx.org/download/nginx-0.7.65.tar.gz
1-1 解压缩 nginx-0.7.65.tar.gz 到 /usr/develop/yagnwr
1-2解压缩jvm-route.zip到/usr/develop/yagnwr
还可以从网站上下载svncheckouthttp://nginx-upstream-jvm-route.googlecode.com/svn/trunk/nginx-upstream-jvm-route-read-only
1-3切换到/usr/develop/yagnwr/nginx-0.7.65
1-4patch-p0</usr/develop/yagnwr/jvm-route/jvm_route.patch
1-5./configure--prefix=/usr/mpsp/nginx-0.7.65--add-module=/home/yangwr/soft/jvm-route/--with-http_stub_status_module
1-6make
1-7 make install2--配置文件
rm-f/usr/mpsp/nginx-0.7.65/nginx.conf
vi /usr/mpsp/nginx-0.7.65/nginx.conf3--修改nginx.conf--针对tomcat
服务器10.110.5.151上的nginx.conf负载做如下配置
upstreamnewjboss{
#ip_hash;
server10.110.5.151:9081max_fails=3fail_timeout=30ssrun_id=a;
server10.110.5.152:9081max_fails=3fail_timeout=30ssrun_id=b;
jvm_route$cookie_JSESSIONID|sessionidreverse;
}
服务器10.110.5.151上的nginx.conf负载做如下配置
upstreamnewjboss{
#ip_hash;
server10.110.5.152:9081max_fails=3fail_timeout=30ssrun_id=b;
server10.110.5.151:9081max_fails=3fail_timeout=30ssrun_id=a;
jvm_route$cookie_JSESSIONID|sessionidreverse;
}4--修改tomcat配置/usr/mpsp/newjboss/conf/server.xml
10.110.5.151修改为
<Engine name="Catalina" defaultHost="localhost" jvmRoute="a">10.110.5.152修改为<Engine name="Catalina" defaultHost="localhost" jvmRoute="b">
5--重启nginx,jbossWeb
注:nginx在cdn,F5后端的情况下,根据ip分发session的策略失效,此时需要根据sessionid来转发,
比如151服务器产生的sessionid以a结尾,服务器152产生的sessionid以b结尾,resin服务器则以a,b开头。