Tomcat主配置文件(server.xml)详解

前言

Tomcat主配置文件(server.xml)是Tomcat服务器的主要配置文件,文件位置在conf目录下,它包含了Tomcat的全局配置信息,包括监听端口、虚拟主机、安全配置、连接器等。

目录

1 server.xml组件类别

2 组件介绍

3 server.xml配置文件详解

4 主要参数详解

 4.1 Connector主要参数详解

 4.2 host参数详解

 4.3 Context参数说明


1 server.xml组件类别

顶级组件:位于整个配置的顶层。如:server。

容器类组件:可以包含其他组件的组件。如:service、engine、host、context。

连接器组件:连接用户请求至Tomcat。如:connector。

被嵌套类组件:位于一个容器中,不能包含其他组件。如value、logger。

2 组件介绍

组件名称

功能介绍

engine

核心容器组件,定义Tomcat服务器内部的容器,与Service元素一起定义了Tomcat服务器的整体架构。catalina引擎,负责通过connector接收用户请求,并处理请求,将请求转至对应的虚拟主机host。

host

类似于httpd中的虚拟主机,一般而言支持基于FQDN的虚拟主机,允许在同一台服务器上运行多个网站或应用程序。

context

定义一个应用程序的上下文,包括Web应用程序的路径、名称、文档根目录等,是一个最内层的容器类组件(不能再嵌套)。配置context的主要目的指定对应的webapp的根目录,类似于httpd的alias,其还能为webapp指定额外的属性,如部署方式等。

connector

定义Tomcat服务器与外部应用程序或客户端之间的连接,接收用户请求,通常用于HTTP或HTTPS通讯,类似于httpd的listen配置监听端口。

Service

定义Tomcat服务器提供的服务,通常包含一个或多个Connector(连接器),但只能有一个引擎engine。

Server

定义Tomcat服务器的全局属性,其中的port属性定义了Tomcat服务器本身监听的端口号。

Valve

通过提供不同类型的阀门,拦截请求并在将其转至对应的webapp前进行某种处理操作,可以用于任何容器中,比如记录日志(access log valve)、基于IP做访问控制(remote address filter valve),实现对Tomcat服务器的访问控制、流量控制、日志记录等功能。

loggor

日志记录器,用于记录组件内部的状态信息,可以用于除context外的任何容器中。

Realm

定义Tomcat服务器的安全认证和授权机制。可以用于任意容器类的组件中,关联一个用户认证库,实现认证和授权。可以关联的认证库有: UserDatabaseRealm(使用JNDI自定义的用户认证库)、MemoryRealm(认证信息定义在tomcat-users.xml中)和JDBCRealm(认证信息定义在数据库中,并通过JDBC连接至数据库中查找认证用户)。

3 server.xml配置文件详解

server.xml 文件原版:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Server port="8005" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!-- APR library loader. Documentation at /docs/apr.html -->
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    <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>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         Java HTTP Connector: /docs/config/http.html
         Java AJP  Connector: /docs/config/ajp.html
         APR (HTTP/AJP) Connector: /docs/apr.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
               maxParameterCount="1000"
               />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
               maxParameterCount="1000"
               />
    -->
    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation. The default
         SSLImplementation will depend on the presence of the APR/native
         library and the useOpenSSL attribute of the AprLifecycleListener.
         Either JSSE or OpenSSL style configuration may be used regardless of
         the SSLImplementation selected. JSSE style configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true"
               maxParameterCount="1000"
               >
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->
    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
         This connector uses the APR/native implementation which always uses
         OpenSSL for TLS.
         Either JSSE or OpenSSL style configuration may be used. OpenSSL style
         configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11AprProtocol"
               maxThreads="150" SSLEnabled="true"
               maxParameterCount="1000"
               >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeyFile="conf/localhost-rsa-key.pem"
                         certificateFile="conf/localhost-rsa-cert.pem"
                         certificateChainFile="conf/localhost-rsa-chain.pem"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <!--
    <Connector protocol="AJP/1.3"
               address="::1"
               port="8009"
               redirectPort="8443"
               maxParameterCount="1000"
               />
    -->

    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <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"?>


<Server> 元素代表整个容器,是Tomcat实例的顶层元素,由org.apache.catalina.Server接口来定义,它包含一个<Service>元素,并且它不能做为任何元素的子元素。
port 指定Tomcat监听shutdown命令端口,终止服务器运行时,必须在Tomcat服务器所在的机器上发出shutdowm命令,该属性是必须的,其端口号可以修改。
shutdown 指定终止Tomcat服务器运行时,发给Tomcat服务器的shutdown监听端口的字符串,该属性必须设置。
<Server port="8005" shutdown="SHUTDOWN">
  <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服务组件
  <Service name="Catalina">


Connector主要参数
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
               maxParameterCount="1000"
               />


Engine 核心容器组件,catalina引擎,负责通过connector接收用户请求,并处理请求,将请求转至对应的虚拟主机host。
defaultHost 指定缺省的处理请求的主机名,它至少与其中的一个host元素的name属性值一样。
    <Engine name="Catalina" defaultHost="localhost">


Realm 表示存放的用户名、密码及role的数据库。 
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>


host参数
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        <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>

4 主要参数详解

 4.1 Connector主要参数详解

Connector是Tomcat服务器与外部应用程序或客户端之间的连接,常见的Connector类型包括HTTP、HTTPS、AJP等。

 

参数

参数说明

Connector

定义Tomcat服务器与外部应用程序或客户端之间的连接,接收用户请求,通常用于HTTP或HTTPS通讯,类似于httpd的listen配置监听端口。

port

指定Connector监听的端口号,用于监听来自客户端的请求。

protocol

连接器使用的协议,指定Connector要使用的协议类型,常见的有HTTP/1.1、HTTP/2、AJP/1.3等。

connectionTimeout

指定超时的时间数(以毫秒为单位),即在指定时间内未收到客户端请求,则连接被关闭。

redirectPort

指定重定向端口,即在使用HTTPS时,自动将HTTP请求重定向到HTTPS。

maxParameterCount

最大可以创建的处理请求的线程数。

 4.2 host参数详解

在Tomcat中,一个物理服务器可以部署多个虚拟主机,每个虚拟主机拥有自己的域名和独立的配置,这些虚拟主机通过Host元素来实现。

 

参数

参数说明

host

Server元素的子元素,代表一个虚拟主机

name

虚拟主机的名称

appBase

指定该虚拟主机的Web应用程序的基础目录,Web应用程序在该目录下部署。

unpackWARs

是否在部署Web应用程序时解压WAR文件,可以提高Web应用程序的访问速度。

autoDeploy

是否自动部署新的Web应用程序,如果设置为true,则Tomcat会自动检测appBase目录下的新的Web应用程序,并进行自动部署。

 4.3 Context参数说明

在Tomcat中,Context参数是指一个Web应用程序的上下文信息,它包含了Web应用程序的配置信息、资源、Servlet等。当一个Web应用程序被部署到Tomcat服务器上时,Tomcat会为该Web应用程序创建一个Context对象,用于管理Web应用程序的运行时状态。

参数

参数说明

Context

表示一个web应用程序,通过为war文件。

docBase

表示Web应用程序的根目录,即Web应用程序的发布目录。应用程序的路径或者是WAR文件存放的路径,也可以使用相对路径,起始路径为此Context所属Host中appBase定义的路径。

path

表示Web应用程序的上下文路径,即访问该Web应用程序的URL路径。

reloadable

这个属性非常重要,如果为true,则tomcat会白动检测应用程序的/WEB-INF/lib和/WEB-INF/classes目录的变化,自动装载新的应用程序,可以在不重启tomcat的情况下改变应用程序。

crossContext

用于指定不同的Web应用程序之间是否可以共享ServletContext对象。如果crossContext被设置为true,则表示允许跨上下文共享ServletContext对象,否则不允许。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/241673.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

003 FeedForward前馈层

一、环境 本文使用环境为&#xff1a; Windows10Python 3.9.17torch 1.13.1cu117torchvision 0.14.1cu117 二、前馈层原理 Transformer模型中的前馈层&#xff08;Feed Forward Layer&#xff09;是其关键组件之一&#xff0c;对于模型的性能起着重要作用。下面将用900字对…

cpp:1:10: fatal error: opencv2/core.hpp: 没有那个文件或目录

前言&#xff1a; 我按照官网方法安装了opencv&#xff0c;运行的也是官网的测试代码&#xff1a; #include <opencv2/core.hpp> #include <opencv2/highgui.hpp> using namespace cv; int main() {printf("hello world")return 0; }

boost1.55 安装使用教程 windows

第一步 &#xff1a;首先在boost官网上下载库压缩包 添加链接描述 选择自己需要的版本进行下载 解压后执行booststrap.bat 用来生成创建b2.exe 和bjam.exe 拓展&#xff1a;.\b2 --help 了解一下有哪些参数可以配置 默认b2.exe编译后&#xff0c;链接到项目如果出现如下错误…

VLAN基本原理

目录 一、VLAN概念及优势 &#xff08;一&#xff09;基本理念 &#xff08;二&#xff09;VLAN的特点 二、VLAN ID 种类、范围及用途 &#xff08;一&#xff09;静态VLAN &#xff08;二&#xff09;动态VLAN &#xff08;三&#xff09;VLAN三种端口类型 &#xff0…

深入理解Java虚拟机---类加载机制

类加载机制 什么是类加载机制类加载的时机类加载的过程加载验证文件格式验证元数据验证字节码验证符号引用验证 准备解析初始化 类加载器双亲委派模型 什么是类加载机制 虚拟机把描述类的数据从 Class 文件加载到内存&#xff0c;并对数据进行校验、转换解析和初始化&#xff…

centOS安装bochsXshell连接centos启动可视化界面

centOS安装bochs 参考&#xff1a;https://blog.csdn.net/muzi_since/article/details/102559187 首先安装依赖环境&#xff1a; yum install gtk2 gtk2-devel yum install libXt libXt-devel yum install libXpm libXpm-devel yum install SDL SDL-devel yum install libXr…

已解决:No goals have been specified for this build. You must specify a vali

[ERROR] No goals have been specified for this build. You must specify a valiTOC 完整报错 No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format : or :[:]:. Available lifecycle phases are: pre-clean, c…

6. Service详解

6. Service详解 文章目录 6. Service详解6.1 Service介绍6.2 Service类型6.3 Service使用6.3.1 实验环境准备6.3.2 ClusterIP类型的Service6.3.3 HeadLess类型的Service6.3.3.1 deployment和statefulset区别6.3.3.2 statefulset deployment 区别 6.3.4 NodePort类型的Service6.…

Trace 在多线程异步体系下传递

JAVA 线程异步常见的实现方式有&#xff1a; new ThreadExecutorService 当然还有其他的&#xff0c;比如fork-join&#xff0c;这些下文会有提及&#xff0c;下面主要针对这两种场景结合 DDTrace 和 Springboot 下进行实践。 引入 DDTrace sdk <properties><java.…

湖农大邀请赛shell_rce漏洞复现

湖农大邀请赛 shell_rce 复现 在 2023 年湖南农业大学邀请赛的线上初赛中&#xff0c;有一道 shell_rce 题&#xff0c;本文将复现该题。 题目内容&#xff0c;打开即是代码&#xff1a; <?phpclass shell{public $exp;public function __destruct(){$str preg_replace…

Shopify怎么避免被封店?封店原因有哪些?

市场研究的一份报告显示&#xff0c;全球跨境电子商务市场预计到2028年将达到30422亿美元&#xff0c;其中&#xff0c;亚太地区是最大的跨境电商市场&#xff0c;据海关统计数据&#xff0c;近五年来&#xff0c;我国跨境电商进出口增长近10倍。跨境电商业务新的增长风口已经到…

图像去噪——PMRID训练自己数据集及推理测试(详细图文教程)

目录 一、源码包准备二、数据集准备2.1 提取数据集名称2.2 .txt报错问题2.2.1 正确格式2.2.2 错误格式 三、修改配置参数四、训练及保存模型权重4.1 训练4.2 保存模型权重文件 五、模型推理测试5.1 导入测试集5.2 测试5.3 测试结果5.3.1 测试场景15.3.2 测试场景2 5.4 推理速度…

jsp+servlet+图书交流平台 有filter过滤器

在线图书推荐与交流平台 随着数字化的进展和人们对持续学习的追求&#xff0c;在线资源变得越来越受欢迎。对于众多读者来说&#xff0c;找到合适的书籍和与其他读者交流阅读体验是非常有价值的。为了满足这一需求&#xff0c;我们提出了一个在线图书推荐与交流平台的设计。此…

千梦网创:赚钱就是服侍好双爹

“爹啊&#xff0c;我没钱用啦&#xff0c;给我啃一下。” 想赚钱&#xff0c;最快的方式就是啃爹。 不管你做什么项目&#xff0c;同行永远都是我们的爹。 跟着爹走&#xff0c;有吃有喝不用愁。 跟着老爹走&#xff0c;蛋花汤里加骨头。 小时候父亲总是把我们高高的举过…

查询mysql服务器当前时区设置、session当前时区设置

使用命令SELECT global.time_zone;可以查询mysql服务器的当前时区设置&#xff0c;例如&#xff1a; 使用命令SELECT session.time_zone;可以查询session的当前时区设置&#xff0c;例如&#xff1a;

Vue 3 开发中遇到的问题及解决方案(fix bug)

开发环境&#xff1a;mac系统&#xff0c;node版本&#xff1a; 16.15.0 版本兼容问题 vite v3.2.4 building for development... hasInjectionContext is not exported by node_modules/pinia/node_modules/vue-demi/lib/index.mjs, imported by node_modules/pinia/dist/pini…

【算法题】冠亚军排名,奖牌榜排名(js)

解法&#xff1a; function solution(lines) {const list [];for (let i 0; i < lines.length; i) {const line lines[i];const [country, gold, silver, bronze] line.split(" ");list.push({country,gold: gold - 0,silver: silver - 0,bronze: bronze - 0…

Java 数据结构篇-用数组、堆实现优先级队列

&#x1f525;博客主页&#xff1a; 【小扳_-CSDN博客】 ❤感谢大家点赞&#x1f44d;收藏⭐评论✍ 文章目录 1.0 优先级队列说明 2.0 用数组实现优先级队列 3.0 无序数组实现优先级队列 3.1 无序数组实现优先级队列 - 入队列 offer(E value) 3.2 无序数组实现优先级队列 - 出…

RocketMQ可视化工具 打包遇到的yarn intall 问题

文章目录 RocketMQ可视化工具1.github上下载2.修改参数3.运行4.打包5.出错6.解决7.重试8.再解决9.很奇怪运行没错&#xff0c;但是测试错啦10.不想深究&#xff0c;直接跳过测试11.展示成功 RocketMQ可视化工具 1.github上下载 下载地址 https://github.com/apache/rocketmq-…

深度学习的目标检测算法综述

信息记录材料 2022年10月 第23卷第10期 【摘要】目标检测是深度学习的一个重要应用&#xff0c;目前在智能驾驶、工业检测相关领域都获得应用&#xff0c;具有重要的现实意义。本文对基于深度学习目标检测算法原理和应用情况进行简述&#xff0c;首先介绍结合区域提取和卷积神经…
最新文章