在nginx.conf中http标签内定义upstream
upstream name { #name自定义一个名字 server ip1:port weight=5; server ip2:port weight=5 }
在server标签内的location/中
loation /{ proxy_pass http name; #使用upstream定义的name proxy_set_header X-Real_IP $remote_addr; client_max_body_size 100m; }
对特殊目录限制权限
location ~ ^/(WEB-INF)/ { denny all; }
tomcat设置
使用memcached-session-manager这个开源项目(http://code.google.com/p/memcached-session-manager,下面简称msm)配置Tomcat和memcached实现session共享。
首先将下面的包下载到Tomcat的lib目录下,这些包都是msm所依赖的包。
[root@localhost ~]# cd /usr/local/tomcat/lib/ [root@localhost lib]# wget http://memcached-session-manager.googlecode.com/files/memcached-session-manager-1.3.0.jar [root@localhost lib]# wget http://memcached-session-manager.googlecode.com/files/msm-javolution-serializer-jodatime-1.3.0.jar [root@localhost lib]# wget http://memcached-session-manager.googlecode.com/files/msm-javolution-serializer-cglib-1.3.0.jar [root@localhost lib]# wget http://spymemcached.googlecode.com/files/memcached-2.4.2.jar [root@localhost lib]# wget http://memcached-session-manager.googlecode.com/files/javolution-5.4.3.1.jar
修改server.xml
<Context docBase="/var/www/html" path="" reloadable="true"> <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:localhost:11211" requestUriIgnorePattern=".*\.(png|gif|jpg|css|js)$" sessionBackupAsync="false" sessionBackupTimeout="100" transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory" copyCollectionsForSerialization="false" /> </Context>
这里的memcachedNodes是填写memcached节点,多个节点时可以以空隔分开,如:
n1:localhost:11211 n2:localhost:11212 /localhost改为安装memcached的服务器的IP
sessionBackupTimeout的单位为分钟
/var/www/html改为Tomcat服务器web根目录的路径
修改后重启TOMCAT和nginx服务
本文出自 “庭前夜末空看雪” 博客,请务必保留此出处http://12550795.blog.51cto.com/12540795/1962761
原文地址:http://12550795.blog.51cto.com/12540795/1962761