日期:2014-05-16  浏览次数:20880 次

linux+nginx+tomcat负载均衡,实现session同步

花了一个上午的时间研究nginx+tomcat的负载均衡测试,集群环境搭建比较顺利,但是session同步的问题折腾了几个小时才搞定,现把我的过程贴上来,以备用。
软件及环境是:
虚拟机上装centos 5.5
IP为:192.168.0.51 装上nginx和tomcat ?6.0.32 命名为 Tomcat1
一台win7上装tomcat ?6.0.32? IP为:192.168.0.50 ?命名为 Tomcat2

首先装nginx,我是参照http://blog.s135.com/nginx_php_v6/?配了一个Nginx + PHP(FastCGI)环境,然后再加上Tomcat的转发。
我的nginx.conf 修改如下

<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->#######################################################################
#
#?This?is?the?main?Nginx?configuration?file.??
#
#?More?information?about?the?configuration?options?is?available?on?
#???
*?the?English?wiki?-?http://wiki.nginx.org/Main
#???*?the?Russian?documentation?-?http://sysoev.ru/nginx/
#
#######################################################################

#
----------------------------------
#?Main?Module?
-?directives?that?cover?basic?functionality
#
#???http:
//wiki.nginx.org/NginxHttpMainModule
#
#
----------------------------------

user??????????????nginx;
worker_processes??
8;

error_log??
/var/log/nginx/error.log;
#error_log??
/var/log/nginx/error.log??notice;
#error_log??
/var/log/nginx/error.log??info;

pid????????
/var/run/nginx.pid;


#
----------------------------------
#?Events?Module?
#
#???http:
//wiki.nginx.or