最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Tomcat主配置文件server.xml詳解

 更新時間:2024年05月14日 11:52:21   作者:Mortalz7  
Tomcat主配置文件server.xml是Tomcat服務(wù)器的主要配置文件,文件位置在conf目錄下,本文就來介紹一下server.xml的具體用法,具有一定的參考價值,感興趣的可以了解一下

前言

Tomcat主配置文件(server.xml)是Tomcat服務(wù)器的主要配置文件,文件位置在conf目錄下,它包含了Tomcat的全局配置信息,包括監(jiān)聽端口、虛擬主機(jī)、安全配置、連接器等。

1 server.xml組件類別

頂級組件:位于整個配置的頂層。如:server。

  • 容器類組件:可以包含其他組件的組件。如:service、engine、host、context。
  • 連接器組件:連接用戶請求至Tomcat。如:connector。
  • 被嵌套類組件:位于一個容器中,不能包含其他組件。如value、logger。

2 組件介紹

組件名稱

功能介紹

engine

核心容器組件,定義Tomcat服務(wù)器內(nèi)部的容器,與Service元素一起定義了Tomcat服務(wù)器的整體架構(gòu)。catalina引擎,負(fù)責(zé)通過connector接收用戶請求,并處理請求,將請求轉(zhuǎn)至對應(yīng)的虛擬主機(jī)host。

host

類似于httpd中的虛擬主機(jī),一般而言支持基于FQDN的虛擬主機(jī),允許在同一臺服務(wù)器上運(yùn)行多個網(wǎng)站或應(yīng)用程序。

context

定義一個應(yīng)用程序的上下文,包括Web應(yīng)用程序的路徑、名稱、文檔根目錄等,是一個最內(nèi)層的容器類組件(不能再嵌套)。配置context的主要目的指定對應(yīng)的webapp的根目錄,類似于httpd的alias,其還能為webapp指定額外的屬性,如部署方式等。

connector

定義Tomcat服務(wù)器與外部應(yīng)用程序或客戶端之間的連接,接收用戶請求,通常用于HTTP或HTTPS通訊,類似于httpd的listen配置監(jiān)聽端口。

Service

定義Tomcat服務(wù)器提供的服務(wù),通常包含一個或多個Connector(連接器),但只能有一個引擎engine。

Server

定義Tomcat服務(wù)器的全局屬性,其中的port屬性定義了Tomcat服務(wù)器本身監(jiān)聽的端口號。

Valve

通過提供不同類型的閥門,攔截請求并在將其轉(zhuǎn)至對應(yīng)的webapp前進(jìn)行某種處理操作,可以用于任何容器中,比如記錄日志(access log valve)、基于IP做訪問控制(remote address filter valve),實(shí)現(xiàn)對Tomcat服務(wù)器的訪問控制、流量控制、日志記錄等功能。

loggor

日志記錄器,用于記錄組件內(nèi)部的狀態(tài)信息,可以用于除context外的任何容器中。

Realm

定義Tomcat服務(wù)器的安全認(rèn)證和授權(quán)機(jī)制??梢杂糜谌我馊萜黝惖慕M件中,關(guān)聯(lián)一個用戶認(rèn)證庫,實(shí)現(xiàn)認(rèn)證和授權(quán)。可以關(guān)聯(lián)的認(rèn)證庫有: UserDatabaseRealm(使用JNDI自定義的用戶認(rèn)證庫)、MemoryRealm(認(rèn)證信息定義在tomcat-users.xml中)和JDBCRealm(認(rèn)證信息定義在數(shù)據(jù)庫中,并通過JDBC連接至數(shù)據(jù)庫中查找認(rèn)證用戶)。

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實(shí)例的頂層元素,由org.apache.catalina.Server接口來定義,它包含一個<Service>元素,并且它不能做為任何元素的子元素。
port 指定Tomcat監(jiān)聽shutdown命令端口,終止服務(wù)器運(yùn)行時,必須在Tomcat服務(wù)器所在的機(jī)器上發(fā)出shutdowm命令,該屬性是必須的,其端口號可以修改。
shutdown 指定終止Tomcat服務(wù)器運(yùn)行時,發(fā)給Tomcat服務(wù)器的shutdown監(jiān)聽端口的字符串,該屬性必須設(shè)置。
<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服務(wù)組件

<Service name="Catalina">

Connector主要參數(shù)

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

Engine 核心容器組件,catalina引擎,負(fù)責(zé)通過connector接收用戶請求,并處理請求,將請求轉(zhuǎn)至對應(yīng)的虛擬主機(jī)host。

defaultHost 指定缺省的處理請求的主機(jī)名,它至少與其中的一個host元素的name屬性值一樣。

<Engine name="Catalina" defaultHost="localhost">

Realm 表示存放的用戶名、密碼及role的數(shù)據(jù)庫。 

      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

host參數(shù)

      <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 主要參數(shù)詳解

 4.1 Connector主要參數(shù)詳解

Connector是Tomcat服務(wù)器與外部應(yīng)用程序或客戶端之間的連接,常見的Connector類型包括HTTP、HTTPS、AJP等。

參數(shù)

參數(shù)說明

Connector

定義Tomcat服務(wù)器與外部應(yīng)用程序或客戶端之間的連接,接收用戶請求,通常用于HTTP或HTTPS通訊,類似于httpd的listen配置監(jiān)聽端口。

port

指定Connector監(jiān)聽的端口號,用于監(jiān)聽來自客戶端的請求。

protocol

連接器使用的協(xié)議,指定Connector要使用的協(xié)議類型,常見的有HTTP/1.1、HTTP/2、AJP/1.3等。

connectionTimeout

指定超時的時間數(shù)(以毫秒為單位),即在指定時間內(nèi)未收到客戶端請求,則連接被關(guān)閉。

redirectPort

指定重定向端口,即在使用HTTPS時,自動將HTTP請求重定向到HTTPS。

maxParameterCount

最大可以創(chuàng)建的處理請求的線程數(shù)。

 4.2 host參數(shù)詳解

在Tomcat中,一個物理服務(wù)器可以部署多個虛擬主機(jī),每個虛擬主機(jī)擁有自己的域名和獨(dú)立的配置,這些虛擬主機(jī)通過Host元素來實(shí)現(xiàn)。

參數(shù)

參數(shù)說明

host

Server元素的子元素,代表一個虛擬主機(jī)

name

虛擬主機(jī)的名稱

appBase

指定該虛擬主機(jī)的Web應(yīng)用程序的基礎(chǔ)目錄,Web應(yīng)用程序在該目錄下部署。

unpackWARs

是否在部署Web應(yīng)用程序時解壓WAR文件,可以提高Web應(yīng)用程序的訪問速度。

autoDeploy

是否自動部署新的Web應(yīng)用程序,如果設(shè)置為true,則Tomcat會自動檢測appBase目錄下的新的Web應(yīng)用程序,并進(jìn)行自動部署。

 4.3 Context參數(shù)說明

在Tomcat中,Context參數(shù)是指一個Web應(yīng)用程序的上下文信息,它包含了Web應(yīng)用程序的配置信息、資源、Servlet等。當(dāng)一個Web應(yīng)用程序被部署到Tomcat服務(wù)器上時,Tomcat會為該Web應(yīng)用程序創(chuàng)建一個Context對象,用于管理Web應(yīng)用程序的運(yùn)行時狀態(tài)。

參數(shù)

參數(shù)說明

Context

表示一個web應(yīng)用程序,通過為war文件。

docBase

表示W(wǎng)eb應(yīng)用程序的根目錄,即Web應(yīng)用程序的發(fā)布目錄。應(yīng)用程序的路徑或者是WAR文件存放的路徑,也可以使用相對路徑,起始路徑為此Context所屬Host中appBase定義的路徑。

path

表示W(wǎng)eb應(yīng)用程序的上下文路徑,即訪問該Web應(yīng)用程序的URL路徑。

reloadable

這個屬性非常重要,如果為true,則tomcat會白動檢測應(yīng)用程序的/WEB-INF/lib和/WEB-INF/classes目錄的變化,自動裝載新的應(yīng)用程序,可以在不重啟tomcat的情況下改變應(yīng)用程序。

crossContext

用于指定不同的Web應(yīng)用程序之間是否可以共享ServletContext對象。如果crossContext被設(shè)置為true,則表示允許跨上下文共享ServletContext對象,否則不允許。

到此這篇關(guān)于Tomcat主配置文件server.xml詳解的文章就介紹到這了,更多相關(guān)Tomcat server.xml內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 淺談Tomcat7的熱部署

    淺談Tomcat7的熱部署

    這篇文章主要介紹了淺談Tomcat7的熱部署,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-06-06
  • Tomcat負(fù)載均衡部署過程

    Tomcat負(fù)載均衡部署過程

    這篇文章主要介紹了Tomcat負(fù)載均衡部署過程,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-06-06
  • 解決tomcat部署下的web項目網(wǎng)頁更改不能自動刷新的問題

    解決tomcat部署下的web項目網(wǎng)頁更改不能自動刷新的問題

    下面小編就為大家?guī)硪黄鉀Qtomcat部署下的web項目網(wǎng)頁更改不能自動刷新的問題。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06
  • 啟動tomcat時 錯誤: 代理拋出異常 : java.rmi.server.ExportException: Port already in use: 1099的解決辦法

    啟動tomcat時 錯誤: 代理拋出異常 : java.rmi.server.ExportException: Port

    這篇文章主要介紹了啟動tomcat時 錯誤: 代理拋出異常 : java.rmi.server.ExportException: Port already in use: 1099的解決辦法的相關(guān)資料,需要的朋友可以參考下
    2016-05-05
  • Tomcat 發(fā)布程序使用cmd查看端口占用、相應(yīng)進(jìn)程、殺死進(jìn)程等的命令

    Tomcat 發(fā)布程序使用cmd查看端口占用、相應(yīng)進(jìn)程、殺死進(jìn)程等的命令

    這篇文章主要介紹了Tomcat 發(fā)布程序使用cmd查看端口占用、相應(yīng)進(jìn)程、殺死進(jìn)程等的命令的相關(guān)資料,需要的朋友可以參考下
    2016-12-12
  • 深入分析Tomcat無響應(yīng)問題及解決方法

    深入分析Tomcat無響應(yīng)問題及解決方法

    Tomcat是Apache 軟件基金會(Apache Software Foundation)的Jakarta 項目中的一個核心項目,由Apache、Sun 和其他一些公司及個人共同開發(fā)而成,通常我們會用它來運(yùn)行java了,下文小編來為各位介紹Tomcat無響應(yīng)問題解決辦法
    2016-05-05
  • 詳解windows 10中Tomcat安裝和部署的教程

    詳解windows 10中Tomcat安裝和部署的教程

    這篇文章主要介紹了windows 10中Tomcat安裝和部署教程,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-11-11
  • 基于Tomcat 數(shù)據(jù)源的原理、配置、使用介紹

    基于Tomcat 數(shù)據(jù)源的原理、配置、使用介紹

    下面小編就為大家?guī)硪黄赥omcat 數(shù)據(jù)源的原理、配置、使用介紹。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • 搭建Tomcat 8源碼開發(fā)環(huán)境的步驟詳解

    搭建Tomcat 8源碼開發(fā)環(huán)境的步驟詳解

    相信大家都知道開源軟件tomcat目前幾乎已經(jīng)是Java web開發(fā)的必備軟件了,目前有很多關(guān)于tomcat的書籍,已經(jīng)通過配置對tomcat進(jìn)行一些跟應(yīng)用業(yè)務(wù)功能的調(diào)優(yōu),但感覺如果僅僅只是了解一些配置,可能稍微少了點(diǎn)什么,下面通過本文深入到源代碼中進(jìn)行學(xué)些和了解。
    2016-10-10
  • Tomcat部署項目的幾種常見方式[親測]

    Tomcat部署項目的幾種常見方式[親測]

    這篇文章主要介紹了Tomcat部署項目的幾種常見方式,文中給大家提到了三種方法,除此之外還有Tomcat熱部署的方式 ,感興趣的朋友跟隨小編一起看看吧
    2018-11-11

最新評論

芜湖市| 林州市| 江津市| 鱼台县| 泸州市| 调兵山市| 密山市| 通江县| 商都县| 保德县| 阳原县| 武安市| 石林| 麦盖提县| 原平市| 廊坊市| 洛阳市| 云霄县| 安庆市| 彰武县| 肥西县| 泊头市| 晴隆县| 莱西市| 镇赉县| 商南县| 苍梧县| 巫山县| 榕江县| 上饶县| 宜兴市| 永吉县| 南充市| 湘阴县| 东乡县| 高要市| 买车| 龙门县| 明星| 丘北县| 涞水县|