虚拟化容器,大数据,DBA,中间件,监控。

Tomcat配置参数详解

25 07月
作者:admin|分类:应用管理

下面是tomcat-8.5.37原生server.xml配置,删除了所有自有注释

Connector主要属性:

    protocol  监听的协议,默认是http/1.1
    port   连接端口号
    minThread  初始化线程数
    maxThread  最大线程数,生产配置800-1000
    minSpareThreads="100" 最大空闲线程
    enableLookups="false"  如果为true,则可以通过调用request.getRemoteHost()进行DNS查询来得到远程客户端的实际主机名,若为false则不进行DNS查询,而是返回其ip地址,生产环境建议设置false
    redirectPort  指定服务器正在处理http请求时收到了一个SSL传输请求后重定向的端口号
    acceptCount="800"  指定当所有可以使用的处理请求的线程数都被使用时,可以放到处理队列中的请求数,超过这个数的请求将不予处理,相当于多线程的队列
    connectionTimeout  指定超时的时间数(以毫秒为单位)
    SSLEnabled  是否开启 sll 验证,在Https 访问时需要开启
    URIEncoding="UTF-8"
     useBodyEncodingForURI="true"
     compression="on"
    compressionMinSize="2048"

    compressableMimeType="text/html,text/xml,text/plain,text/javascript,text/css,application/x-json,application/json,application/x-javascript"

    <?xml version="1.0" encoding="UTF-8"?>
    <!--8005用来执行shutdown命令,只能被127.0.0.1使用-->
    <Server port="8005" shutdown="SHUTDOWN">
      <!--Listener(监听器),类似于webx.xml中的配置-->
      <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
      <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
      <!--防止内存溢出-->
      <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
      <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
      <!--全局资源-->
      <GlobalNamingResources>
        <Resource name="UserDatabase" auth="Container"
                  type="org.apache.catalina.UserDatabase"
                  description="User database that can be updated and saved"
                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                  pathname="conf/tomcat-users.xml" />
      </GlobalNamingResources>
      <Service name="Catalina">
        <!--Connector 接收用户请求转化为Request-->
        <!--protocol协议版本-->
        <!--redirectPort=https重定向端口,此时8443端口要有对应的Connector-->
        <Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" />
        <!--AJP协议=Apache与tomcat进行反向代理的私有协议,注:AJP是二进制协议,http是文本协议
        这个端口用不到的,此项配置可以注释,省一个端口-->
        <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
        
        <!--Engine(引擎)用来处理请求,根据域名分发到Host,当没有域名可以区分Host的时候默认分发到
        defaultHost(localhost),
        defaultHost相当于nginx中的defaultServer-->
        <Engine name="Catalina" defaultHost="localhost">
          <Realm className="org.apache.catalina.realm.LockOutRealm">
            <!--Realm(领域) 把资源注册到Engine
            UserDatabase=tomcat-users.xml-->
            <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                   resourceName="UserDatabase"/>
          </Realm>
          <!--Host(虚拟机)
          appBase应用的相对路径
          unpackWARs自动解压war包
          autoDeploy自动部署-->
          <Host name="localhost"  appBase="webapps"
                unpackWARs="true" autoDeploy="true">
            <!--Valve(阀门),相当于过滤器,此处配置用于打印日志,可用于IP过滤、限流 -->
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="localhost_access_log" suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
     
          </Host>
        </Engine>
      </Service>
    </Server>

自定义配置

    <?xml version="1.0" encoding="UTF-8"?>
    <!--8005用来执行shutdown命令,只能被127.0.0.1使用
         可以删除port和shutdown配置-->
    <Server port="8005" shutdown="SHUTDOWN">
      <!--Listener(监听器),类似于webx.xml中的配置-->
      <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
      <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
      <!--防止内存溢出-->
      <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
      <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
      <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
      <!--全局资源-->
      <GlobalNamingResources>
        <Resource name="UserDatabase" auth="Container"
                  type="org.apache.catalina.UserDatabase"
                  description="User database that can be updated and saved"
                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                  pathname="conf/tomcat-users.xml" />
      </GlobalNamingResources>
      <Service name="Catalina">
        <!--Connector 接收用户请求转化为Request
                 protocol协议版本
            redirectPort=https重定向端口,此时8443端口要有对应的Connector
            https默认端口443-->
        <Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443"                 
                    />
        <Connector port="80" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443"                 
                   minSpareThreads="200"                       
                   maxThread="1000"
                   acceptCount="1000"
                   enableLookups="false"
                   URIEncoding="UTF-8"
                   useBodyEncodingForURI="true"
                   compression="on"
                   ompressionMinSize="2048"
                   compressableMimeType="text/html,text/xml,text/plain,
                   text/javascript,text/css,application/x-json,
                   application/json,application/x-javascript"            
                   />
        <!--AJP协议=Apache与tomcat进行反向代理的私有协议,注:AJP是二进制协议,http是文本协议
                    这个端口用不到的,此项配置可以注释,省一个端口-->
        <!--<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />-->
     
            <!--Engine(引擎)用来处理请求,当没有域名可以区分Host的时候默认分发到defaultHost(localhost),
                    defaultHost相当于nginx中的defaultServer-->
        <Engine name="Catalina" defaultHost="localhost">
          <Realm className="org.apache.catalina.realm.LockOutRealm">
                <!--Realm(领域) 把资源注册到Engine
                                    UserDatabase=tomcat-users.xml-->
            <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
                   resourceName="UserDatabase"/>
          </Realm>
          <!--Host(虚拟机)
                      appBase应用的相对路径
              unpackWARs自动解压war包
              autoDeploy自动部署-->
          <Host name="localhost"  appBase="webapps"
                unpackWARs="true" autoDeploy="true">
                    <!--Valve(阀门),相当于过滤器,此处配置用于打印日志,可用于IP过滤、限流 -->
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="localhost_access_log" suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
     
          </Host>
     
           <Host name="www.testtomcat.com"  appBase="/test/tomcat"
                unpackWARs="true" autoDeploy="true">
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="test_tomcat_access_log" suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
           <Context path="/a" docBase="hello" reloadable="true"/>
          </Host>
     
        </Engine>
      </Service>
    </Server>

另外可以在conf/域名/ROOT.xml进行配置
---------------------
作者:元澈
来源:CSDN
原文:https://blog.csdn.net/ab7253957/article/details/85260211
版权声明:本文为博主原创文章,转载请附上博文链接!

浏览871 评论0
返回
目录
返回
首页
Tomcat安全配置参考 笔记本安装win2016,intel ac3165无线断网