首页 / TOMCAT / nginx +tomcat配置
nginx +tomcat配置
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了nginx +tomcat配置,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4079字,纯文字阅读大概需要6分钟。
内容图文
![nginx +tomcat配置](/upload/InfoBanner/zyjiaocheng/1199/328164e7da444c30a38fef6e5558372b.jpg)
nginx充当一个反向代理器功能,就是把请求分发到真正执行的tomcat上,在这里不讨论其具体实现,只提供集群部署说明,经测试可用,并且于10000以上并发数下优异与Apache+tomcat集群。
<SPAN style=‘font-family: "宋体"; font-size: 12pt; font-weight: bold; mso-spacerun: "yes";‘> Nginx版本 nginx-1.5.10
<SPAN style=‘font-family: "宋体"; font-size: 12pt; font-weight: bold; mso-spacerun: "yes";‘> Memcached版本 memcached-win32-1.4.4-14
<SPAN style=‘font-family: "宋体"; font-size: 12pt; font-weight: bold; mso-spacerun: "yes";‘> Tomcat版本 apache-tomcat-7.0.29
<SPAN style=‘font-family: "宋体"; font-size: 12pt; font-weight: bold; mso-spacerun: "yes";‘>1 配置nginx
<SPAN style=‘font-family: "宋体"; font-size: 12pt; font-weight: bold; mso-spacerun: "yes";‘> 下载好nginx之后找一个目录解压大概内容如下:
以上截图与解压出来的配置文件的不同在于“userstram localhost{}”中的内容,这里就是我们配置tomcat集群的设置,所以里面的应当对应你自己的tomcat所在地址
server属性为nginx本身,所监听端口默认为80,请确认该端口可用,之后可以看到有多个"location",这里配置了动静分离,所谓动静分离就是说静态的部分比如Html,css,js等资源交给nginx本身处理,而动态的jsp则转发给相关的tomcat集群处理,一定程度上可以提升项目的加载速率。具体“location”相关正则说明参见ttp://www.2cto.com/os/201212/176520.html
这里不多做说明。
<SPAN style=‘font-family: "宋体"; font-size: 10.5pt; mso-spacerun: "yes";‘>2 配置tomcat,下载免安装的tomcat,复制两份分别为tomcat1.tomcat2
<SPAN style=‘font-family: "宋体"; font-size: 10.5pt; mso-spacerun: "yes";‘>3 分别修改tomcat1,tomcat2的 server.xml文件
1) tomcat1的server.xml文件修改
A)修改 <Connector port="8080" protocol="HTTP/1.1" URIEncoding="UTF-8"
connectionTimeout="20000"
redirectPort="8443" />为
<Connector port=" 8881 " protocol="HTTP/1.1" URIEncoding="UTF-8"
connectionTimeout="20000" maxThreads="800" minSpareThreads="100" maxSpareThreads="300" acceptCount="300"
redirectPort="8443" />
2)tomcat2的server.xml文件修改
A)修改 <Connector port="8080" protocol="HTTP/1.1" URIEncoding="UTF-8"
connectionTimeout="20000"
redirectPort="8443" />为
<Connector port=" 8883 " protocol="HTTP/1.1" URIEncoding="UTF-8"
connectionTimeout="20000"
redirectPort="8443" />
<SPAN style=‘font-family: "宋体"; font-size: 10.5pt; mso-spacerun: "yes";‘> 这里修改的端口号要对应nginx配置文件中“userstram localhost{}”里面地址的端口,当然如果你想用ip不同的两台电脑当tomcat服务器,那么端口都不需要更改。
<SPAN style=‘font-family: "宋体"; font-size: 10.5pt; mso-spacerun: "yes";‘>4 修改tomcat1,tomcat2的context.xml文件(这里的作用是实现session共享)
配置之前请先下载memcached 解压,将里面的jar包放到tomcat lib文件夹下,(两个tomcat都要放)之后修改context.xml文件
其中的ip地址应当为memcached运行所在主机的ip,最好把他放在与nginx同一台主机上运行。
创建test.jsp文件,分别放于两个tomcat的webapp文件夹下
1 <%@ page contentType="text/html; charset=GBK" %> 2 <%@ page import="java.util.*" %> 3 <html><head><title>Cluster App Test</title></head> 4 <body> 5 Server Info: 6 <% 7 out.println(request.getLocalAddr() + " : " + request.getLocalPort()+"<br>");%> 8 <% 9 out.println("<br> ID " + session.getId()+"<br>"); 10 String dataName = request.getParameter("dataName"); 1112if (dataName != null && dataName.length() > 0) { 13 String dataValue = request.getParameter("dataValue"); 14 session.setAttribute(dataName, dataValue); 15 } 1617 out.print("<b>Session 列表</b>"); 1819 Enumeration e = session.getAttributeNames(); 2021while (e.hasMoreElements()) { 22 String name = (String)e.nextElement(); 23 String value = session.getAttribute(name).toString(); 24 out.println( name + " = " + value+"<br>"); 25 System.out.println( name + " = " + value); 26 } 27 %> 28 <form action="test.jsp" method="POST"> 29 名称:<input type=text size=20 name="dataName"> 30 <br> 31 值:<input type=text size=20 name="dataValue"> 32 <br> 33 <input type=submit> 34 </form> 35 </body> 36 </html>
一切准备就绪,打开memcached,直接双击就好,启动两个tomcat,启动nginx(直接双击,闪一下就消失也没有关系,用任务管理器查看是否有nginx的进程,如果有则说明成功启动)
打开浏览器分别输入“http://localhost:8881/test.jsp”,“http://localhost:8883/test.jsp”,看到sessionID相同,但是端口不同,再输入“http://localhost:8033/test.jsp”,不断刷新,看到sessionID不变,端口不停变化。如下:
说明测试成功。另附压力测试软件Microsoft Web Application Stress Tool
根据该测试软件得出的测试数据如下:
<SPAN style=‘font-family: "宋体"; font-size: 12pt; font-weight: bold; mso-spacerun: "yes";‘>
原文:http://www.cnblogs.com/wq123/p/3573816.html
内容总结
以上是互联网集市为您收集整理的nginx +tomcat配置全部内容,希望文章能够帮你解决nginx +tomcat配置所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。