1.nginx安装
nginx1.5.0
E:\nginx-1.5.0\conf,添加proxy.conf,gzip.conf
修改配置文件nginx.conf
#Nginx所用用户和组 #user niumd niumd; #工作的子进程数量(通常等于CPU数量或者2倍于CPU) worker_processes 1; #错误日志存放路径 #error_log logs/error.log; #error_log logs/error.log notice; error_log logs/error.log info; #指定pid存放文件 pid logs/nginx.pid; events { #使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue #use epoll; #允许最大连接数 worker_connections 2048; } 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 off; access_log logs/access.log; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; client_header_buffer_size 1k; large_client_header_buffers 4 4k; sendfile on; tcp_nopush on; tcp_nodelay on; #keepalive_timeout 75 20; #include gzip.conf; include proxy.conf; upstream mytest { #根据ip计算将请求分配各那个后端tomcat,许多人误认为可以解决session问题,其实并不能。 #同一机器在多网情况下,路由切换,ip可能不同 #ip_hash; #weigth参数表示权值,权值越高被分配到的几率越大 server 192.168.1.106:8081; server 192.168.1.106:8082; } server { listen 8099; server_name 192.168.1.106; location / { #定义服务器的默认网站根目录位置 root html; #定义首页索引文件的名称 index index.html index.htmindex.jsp; proxy_connect_timeout 3; proxy_send_timeout 30; proxy_read_timeout 30; proxy_pass http://mytest; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
proxy.conf
proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 300; proxy_send_timeout 300; proxy_read_timeout 300; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k;
gzip.conf
gzip on; gzip_min_length 1024; gzip_buffers 4 8k; gzip_comp_level 9; gzip_proxied any; gzip_types application/xml application/javascript application/x-javascript application/atom+xml application/rss+xml; gzip_types text/css text/html text/javascript text/js text/plain text/xml;
2.tomcat7
准备tomcat7.1和tomcat7.2
tomcat7.1 server.xml 修改端口
<Server port="8101" shutdown="SHUTDOWN"> <Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/> <Connector port="8201" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
<Server port="8102" shutdown="SHUTDOWN"> <Connector port="8082" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8202" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">
3.memcached session共享
3.0.安装memcached 1.4.4-14 window64
3.1.context.xml 7.1和7.2添加内容 tomcat和memcached整合
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:192.168.1.106:11211" sticky="false" sessionBackupAsync="false" lockingMode="none" sessionBackupTimeout="100" requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory" />
3.2.需要的jar包 加入到E:\Tomcat\tomcat7.2\lib和E:\Tomcat\tomcat7.1\lib
couchbase-client-1.0.3.jar memcached-2.6.jar memcached-session-manager-1.5.1.jar memcached-session-manager-tc7-1.5.1.jar msm-javolution-serializer-1.5.1.jar msm-kryo-serializer-1.5.1.jar msm-xstream-serializer-1.5.1.jar kryo-1.03.jar kryo-serializers-0.10.jar minlog-1.2.jar reflectasm-0.9.jar
4.index.jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="java.text.SimpleDateFormat"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> 服务器信息: <% String dtm = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()); System.out.println("["+request.getLocalAddr()+":"+ request.getLocalPort()+"]" + dtm); out.println("<br>["+request.getLocalAddr()+":" +request.getLocalPort()+"]" + dtm+"<br>"); %> session分发: <% //session.setAttribute("name","dennisit"); //HttpSession session = request.getSession(true); System.out.println("[session分发] session id:"+session.getId()); out.println("<br>[session分发] session id: " + session.getId()+"<br>"); %> </body> </html>
参考资料:
http://www.linuxidc.com/Linux/2012-09/71264.htm
memcached配置
http://blog.csdn.net/a__java___a/article/details/8738932
windows下安装多个tomcat服务
http://my.oschina.net/ihanfeng/blog/286062