|
一直在用Tomcat,但是也只停留在使用上,这几天有机会想深入学习下Tomcat,所以开始仔细学习Tomcat,在看了尚学堂-张志宇老师的Jsp/Servlet的视频时,中间提及了一些Tomcat的详细内容。下面具体说说Tomcat安装文件夹下的conf目录下server.xml的具体用途。
一下文章为张志宇老师整理,在此感谢他!希望对大家有所帮助!
1Server
1.1IntheTomcatworld,aServerrepresentsthewholecontainer.TomcatprovidesadefaultimplementationoftheServerinterface.,andthisisrarelycustomizedbyusers.
1.2在tomcat的世界里,一个server代表整个容器.Tomcat提供了一个默认的org.apache.catalina接口的实现.用户很少修改这个默认的实现
2Service
2.1AServiceisanintermediatecomponentwhichlivesinsideaServerandtiesoneormoreConnectorstoexactlyoneEngine. TheServiceelementisrarelycustomizedbyusers,asthedefaultimplementationissimpleandsufficient:Serviceinterface.
2.2一个Service是一个中间件,存在在一个Server的内部,将一个或者多个Connectors绑定到一个特定的Engine上.默认的实现已经足够用了.是org.apache.catalina.Service接口的一个实现.
A"Service"isacollectionofoneormore"Connectors"thatshareasingle"Container"
一个Service是一个或者多个Connectors的集合,这些个Connectors共享一个容器。
3Engine
3.1AnEnginerepresentsrequestprocessingpipelineforaspecificService.AsaServicemayhavemultipleConnectors,theEn ginereceivedandprocessesallrequestsfromtheseconnectors,handingtheresponsebacktotheappropriateconnectorfortransmissiontotheclient.TheEngineinterfacemaybeimplementedtosupplycustomEngines,thoughthisisuncommon.
3.2一个Engine代表一个特定的Service的请求处理的管道.因为一个Service可以有多个Connectors,Engine接收并且处理从这些Connectors过来的所有的请求.并且将结果送回合适的connector并发送给客户端.
3.3可以实现org.apache.catalina.InterfaceEngine接口来提供定制的Engines,虽然一般不需要这样做.
3.4NotethattheEnginemaybeusedforTomcatserverclusteringviathejvmRouteparameter.ReadtheClusteringdocumentati onformoreinformation.
4Host
4.1AHostisanassociationofanetworkname,e.g.www.yourcompany.com,totheTomcatserver.AnEnginemaycontainmulti plehosts,andtheHostelementalsosupportsnetworkaliasessuchasyourcompany.comandabc.yourcompany.com.UsersrarelycreatecustomHostsbecausetheStandardHostimplementationprovidessignificantadditionalfunctionality.
4.2一个Host将一个域名和tomcat联系起来.一个Engine可以包含多个hosts,并且一个Host还支持网络别名(例如yourcompany.com或者abc.yourcompany.com).用户很少去实现一个org.apache.catalina.InterfaceHost接口,因为org.apache.catalina.core.StandardHost这个默认的实现已经提供了丰富的扩展功能了
5Connector
5.1AConnectorhandlescommunicationswiththeclient.TherearemultipleconnectorsavailablewithTomcat,allofwhichimplementtheConnectorinterface.TheseincludetheCoyoteconnectorwhichisusedformostHTTPtraffic,especiallywhenrunningTomcatasastandaloneserver,andtheJK2connectorwhichimplementstheAJPprocotolusedwhenconnectingTomcattoanApacheHTTPDserver.Creatingacustomizedconnectorisasignificanteffort.
5.2一个Connector处理和客户端的通信.tomcat有多个connectors.这些个connectors都实现了Connector接口.
5.3创建一个定制的connector是非常复杂的.
5.4AJP是为Tomcat与HTTP服务器之间通信而定制的协议,能提供较高的通信速度和效率。在配置Tomcat与HTTP服务器集成中,读者可以不必关心AJP协议的细节。关于AJP的知识也可以参考网址:
5.5Tomcat最主要的功能是提供Servlet/JSP容器,尽管它也可以作为独立的JavaWeb服务器,它在对静态资源(如HTML文件或图像文件)的处理速度,以及提供的Web服务器管理功能方面都不如其他专业的HTTP服务器,如IIS和Apache服务器。
5.6因此在实际应用中,常常把Tomcat与其他HTTP服务器集成。对于不支持Servlet/JSP的HTTP服务器,可以通过Tomcat服务器来运行Servlet/JSP组件。
5.7当Tomcat与其他HTTP服务器集成时,Tomcat服务器的工作模式通常为进程外的Servlet容器,Tomcat服务器与其他HTTP服务器之间通过专门的插件来通信。
5.8Tomcat与HTTP服务器集成的原理:Tomcat服务器通过Connector连接器组件与客户程序建立连接,Connector组件负责接收客户的请求,以及把Tomcat服务器的响应结果发送给客户。默认情况下,Tomcat在server.xml中配置了两种连接器:
l<Connectorport="8080"protocol="HTTP/1.1"connectionTimeout="20000"redirectPort="8443"/>
l<Connectorport="8009"protocol="AJP/1.3"redirectPort="8443"/>
5.9第一个连接器监听8080端口,负责建立HTTP连接。在通过浏览器访问Tomcat服务器的Web应用时,使用的就是这个连接器。
5.10第二个连接器监听8009端口,负责和其他的HTTP服务器建立连接。在把Tomcat与其他HTTP服务器集成时,就需要用到这个连接器。
5.11Tomcat提供了专门的JK插件来负责Tomcat和HTTP服务器的通信。应该把JK插件安置在对方的HTTP服务器上。
5.12对于不同的HTTP服务器,Tomcat提供了不同的JK插件的实现模块
l与Windows下的ApacheHTTP服务器集成:mod_jk_2.0.46.dll
l与Linux(RedHet)下的ApacheHTTP服务器集成:mod_jk.so-ap2.0.46-rh72..46-rh72
l与IIS服务器集成:isapi_redirect.dll
5.13AJP是为Tomcat与HTTP服务器之间通信而定制的协议,能提供较高的通信速度和效率。
5.14关于AJP的知识也可以参考网址:
http://jakarta.apache.org/builds/jakarta-tomcat-connectors/jk2/doc/common/AJPv13.html
5.15如果两个Tomcat服务器都在同一台机器上运行,则至少应该对其中一个Tomcat服务器的以上3个端口号都进行修改。
6Context
6.1AContextrepresentsawebapplication.AHostmaycontainmultiplecontexts,eachwithauniquepath.TheContextinterfacemaybeimplementedtocreatecustomContexts,butthisisrarelythecasebecausetheStandardContextprovidessignificantadditionalfunctionality.
6.2一个Context代表一个web应用程序。一个Host可以包含多个contexts。每一个有不同的访问地址。
6.3可以实现Context接口来创建自己的Contexts。但很少这样用,因为StandardContext已经提供了丰富的额外的功能
|
|
|