利用nginx+tomcat+memcached组建web服务器负载均衡(2)
接下来是修改tomcat的配置文件$CATALINA_HOME/conf/context.xml,调整成新的session存储方式。配置文件中加入以下内容:
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:127.0.0.1:11211"
sticky="false"
lockingMode="auto"
sessionBackupAsync="false"
sessionBackupTimeout="1000"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
在$CATALINA_HOME/conf/logging.properties文件中添加de.javakaffee.web.msm.level=FINE,就可以在catalina.out的日志中看到详细的session存取情况。
另外在Manager配置中加上requestUriIgnorePattern=".*\.(png|gif|jpg|css|js)$",用chrome浏览器测试发现居然sessionID会突然变掉,然后就被拦截器给跳回首页了。去掉就一切正常,但拦截器只会去检测action的,按理说应该完全没关系,望高人指点!
3.3 nginx配置
nginx非常简单,只要在upstream里面多配置几个server就可以了,这里把我的配置贴出来:
#user nobody;
worker_processes 16;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;
client_body_buffer_size 128k;
sendfile on;
tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_types text/plain application/xml application/x-javascript;
相关新闻>>
- 发表评论
-
- 最新评论 更多>>