First of all, with questions

Question 1 : Where to configure ?

The core configuration is in Tomcat Under the table of contents conf/ In the catalog server.xml In file

Question two : How to configure ?

as follows

  • Tomcat As a server configuration , Mainly server.xml ⽂ Configuration of components ;
  • server.xml It contains Servlet Configuration of the container , namely Catalina Configuration of ;

One , The main label structure

Server Root element , establish ⼀ individual Server example ,⼦ The label has Listener、GlobalNamingResources、Service
<!-- Define a listener -->
<!-- Define the global scope of the server JNDI resources -->
<!-- Definition ⼀ individual Service service ,⼀ individual Server There can be multiple tags Service Service instance -->

Two ,Server label

Tag attributes :

  • port
  • shutdown

explain Tomcat To listen to port Port to perform the shutdown

port: Turn off the monitor on the server ⼝
shutdown: The command string to shut down the server
<Server port="8005" shutdown="SHUTDOWN">
<!-- With ⽇ Log form output server 、 operating system 、JVM Version information for -->
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!-- Security listener. Documentation at /docs/config/listeners.html
<Listener className="" />
<!--APR library loader. Documentation at /docs/apr.html -->
<!-- load ( Server startup ) and The destruction ( The server is down ⽌) APR. If you can't find it APR library , Will output ⽇ Records , Does not affect Tomcat start-up -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<!-- avoid JRE Memory leak problem -->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<!-- load ( Server startup ) and The destruction ( The server is down ⽌) Global naming service -->
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<!-- stay Context stop ⽌ Time reconstruction Executor Threads in the pool , To avoid ThreadLocal Related memory leaks -->
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <!-- Global JNDI resources Documentation at /docs/jndi-resources-howto.html
GlobalNamingResources The global naming service is defined in
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
<Resource name="UserDatabase" auth="Container"
description="User database that can be updated and saved"
pathname="conf/tomcat-users.xml" />
<!-- 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">

Child tags :

  • Listener

    • VersionLoggerListener( With ⽇ Log form output server 、 operating system 、JVM Version information for )
    • AprLifecycleListener ( load ( Server startup ) and The destruction ( The server is down ⽌) APR. If you can't find it APR library , Will output ⽇ Records , Does not affect Tomcat start-up )
    • JreMemoryLeakPreventionListener ( avoid JRE Memory leak problem )
    • GlobalResourcesLifecycleListener ( load ( Server startup ) and The destruction ( The server is down ⽌) Global naming service )
    • ThreadLocalLeakPreventionListener ( stay Context stop ⽌ Time reconstruction Executor Threads in the pool , To avoid ThreadLocal Related memory leaks )
  • GlobalNamingResources ( The global naming service is defined in )

  • Service ( as follows )

The label above ListenerGlobalNamingResources In general, keep the default , There is no need to operate outside , The point is Service label

3、 ... and ,Service label

<Service name="Catalina">

This label ⽤ To create Service example , By default ⽤ org.apache.catalina.core.StandardService. By default ,Tomcat Only... Is specified Service The name of , The value is "Catalina".

Child tags :

  • Listener (Listener ⽤ For Service add to ⽣ Life cycle monitor )
  • Executor (⽤ To configure Service Shared thread pool , to Connector Use )
  • Connector (⽤ To configure Service Included linker )
  • Engine (⽤ To configure Service The linker in the Servlet Container engine )

Four ,Executor label

Used to define the shared thread pool .

The default is commented out , And the attributes are incomplete . So how to use it ?

By default ,Service No shared thread pool configuration added . If we want to add ⼀ A thread pool , You can add the following configuration under :

<Executor name="commonThreadPool"

attribute :

  • name: Thread pool name ,⽤ On Connector It is specified in
  • namePrefix: The name prefix of each thread created ,⼀ A separate thread name is namePrefix+threadNumber
  • maxThreads: The most ⼤ Number of threads
  • minSpareThreads: Number of active threads , That's the core ⼼ Number of pool threads , These threads are not destroyed , Meeting ⼀ Direct existence
  • maxIdleTime: Thread idle time , After that time , Idle threads are destroyed , The default value is 6000(1 minute ), Company millisecond
  • maxQueueSize: Being held in ⾏ The top one ⼤ Number of threads queued ⽬, The default is Int The most ⼤ value , That is to say ⼴ Righteous ⽆ limit . except ⾮ A special case , This value does not need to be changed , Otherwise, the request will not be processed ⽣
  • prestartminSpareThreads: Whether to start when starting thread pool minSpareThreads Some threads . The default value is false, It doesn't start
  • threadPriority: Thread priority in thread pool , The default value is 5, Value from 1 To 10
  • className: Thread pool implementation class , When not specified , The default implementation class is :

    org.apache.catalina.core.StandardThreadExecutor. If you want to make ⽤⾃ Define thread pool ⾸ First, we need to implement org.apache.catalina.Executor Pick up ⼝

5、 ... and ,Connector label

Connector label ⽤ When creating linker instances, by default ,server.xml Two linkers are configured ,⼀ individual ⽀ a HTTP agreement ,⼀ individual ⽀ a AJP agreement ,⼤ Most of the time , We don't need to add linker configuration , It's just that we need to update the existing linker ⾏ Optimize .

<!--org.apache.coyote.http11.Http11NioProtocol , ⾮ Blocking type  Java NIO  The linker -->
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

attribute :

  • port: End ⼝ Number ,Connector ⽤ Create a server in Socket Go in parallel ⾏ monitor , To wait for the client to request a link . If the property is set to by 0, Tomcat It will be randomly selected ⼀ Personal ⽤ End of ⼝ No. for the present Connector send ⽤
  • protocol: At present Connector ⽀ Access protocol held by . The default is HTTP/1.1 , And pick ⽤⾃ Dynamic switching mechanism selection ⼀ Based on JAVA NIO Or based on local APR Linker ( Depending on whether the local area contains Tomcat Local library decision of )
  • connectionTimeOut: Connector Wait timeout after receiving link , The unit is millisecond . -1 No overtime .
  • redirectPort: At present Connector No ⽀ a SSL request , received ⼀ A request , And it's also in line with security-constraint constraint , need SSL transmission ,Catalina⾃ Move to redirect the request to the specified end ⼝. for instance : If the interview is 8080 port , And then it found out it was a https Request , Then he'll forward it to 8443 port , Of course, you can also visit 8443 port
  • executor: Specifies the name of the shared thread pool ( Namely Executor Labeled name attribute ), It can also be done through maxThreadsminSpareThreads Configure the internal thread pool .
  • URIEncoding: ⽤ In the specified code URI Character encoding of , Tomcat8.x The default encoding of the version is UTF-8 , Tomcat7.x The version defaults to ISO8859-1

Shared thread pool is available :

<Connector port="8080"
acceptCount="1000" // Often with maxThreads bring into correspondence with
maxConnections="1000" // Often with maxThreads bring into correspondence with
compression="on" // Do you want to start gzip Compress
compressionMinSize="2048" // The minimum size of the compression process , Beyond this size to compress
disableUploadTimeout="true" // Give to alone servlet Relax the overtime
URIEncoding="UTF-8" />

You can see Connector Labels and Executor There are maxThreads and minSpareThreads label .

every last Connector You can define a thread pool by yourself , If each Connector It's a waste to define your own thread pool . So why not use one ? So there was Executor Tag to define a shared thread pool .

6、 ... and ,Engine label

Engine Express Servlet engine

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

attribute :

  • name:⽤ To designate Engine The name of , The default is Catalina
  • defaultHost: By default ⽤ Virtual host name of , When the client requests to the host ⽆ Effective time , Will be left to the default virtual host , The default is localhost

Child tags :

  • Cluster: The label for clustering
  • Realm: Verify the security label
  • Host:⽤ To configure ⼀ Virtual hosts

7、 ... and ,Host label

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

Tag attributes :

  • appBase: The location of the program on this site , It can be absolute path or relative path .webapps It's the relative path , stay tomcat Under the root directory of
  • unpackWARs: The default is true, hold war Unpack the package into a folder
  • autoDeploy: Automatic deployment , Automatically deploy when resources change , Similar to hot deployment

Child tags :

<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" />

When the request comes , Keep the log ,

  • Store in directory Value Directory
  • prefix: Log file prefix
  • suffix: Log file suffix
  • pattern: Printed log format

start-up Tomcat Browser input :http://localhost:8080

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

hostname yes localhost,appBase yes webapps, Go to webapps Find the application folder under the folder , Is not specified , Go by default ROOT Under the folder :

Let's do an experiment :

  1. hold host Make a copy of the label , Two host Labeled name Respectively, Respectively webappswebapps2

  2. Get into Tomcat root directory , hold webapps Copy one to the root , Name it webapps2

  3. For the convenience of distinguishing , hold webapps2/ROOT/index.jsp Medium Home Change it to Home-webapps2

  4. Restart Tomcat
  5. To configure hosts file

  6. Visit the browser http://localhost:8080、 and http

    【Tomcat】Tomcat Server Core Configuration description and label more related articles

    1. JSP Learning notes ( 3、 ... and ): ordinary Tomcat Web The server

      Be careful : Every time the Tomcat After the configuration file is modified , Must restart Tomcat stay E Discoid DATA Create in folder TomcatDemo Folder , And will Tomcat Under the installation path webapps/ROOT Medium WEB-INF Folder copy ...

    2. Centos The structures, tomcat https Server details ( original )

      One . install java jdk Configure environment variables 1. Uninstall the original openjdk yum -y remove java-1.7.0-openjdk* yum -y remove tzdata-java.noarc ...

    3. virtualbox build ubuntu server nginx+mysql+tomcat web The server 1 ( To be continued )

      virtualbox build ubuntu server nginx+mysql+tomcat web The server 1 ( To be continued ) First contact linux, I do not know! linux It's really powerful , And then use virtualbox ...

    4. How to access the local Internet tomcat web The server 【 turn 】

      from : How to access the local Internet tomcat web The server author : XHKJOE Release time :2015-07-1 ...

    5. Nginx+Tomcat+Https Server load balancing configuration

      This article is out of date ! Make up a new one : Because of the need to , We have to build a nginx+tomcat+https Server for , What I found on the Internet is always ...

    6. Tomcat 7 Server thread model

      Tomcat 7 Server network processing is mainly composed of NioEndpoint, The main process of handling client connection is shown in the figure Acceptor And Worker They are in the form of thread pools ,Poller It's a single thread . Be careful , And BIO The realization of one ...

    7. The embedded Tomcat Web Use of servers

      Running web Engineering time , Always start up frequently tomcat, Use embedded tomcat It can reduce some repetitive operations . 1. download Unzip the folder and copy it to the project . http://archive ...

    8. Tomcat——Tomcat The use of,

      Tomcat brief introduction Official website : Tomcat GitHub Address : Tomcat yes Apach ...

    9. WCF Server certificate configuration description - There is no private key that can exchange keys , Or the process may not have access to the private key

      WCF Server certificate configuration description 1. Create certificate : makecert.exe -sr LocalMachine -ss My -a sha1 -n CN=XXX -sky exchange -pe explain : -s ...

    10. [tomcat] tomcat+nginx Load balancing configuration

      First download , install tomcat. modify tomcat port , modify server.xml: 1. modify tomcat port ( Default 8080) <Connector port="8383" pro ...

    Random recommendation

    1. jQuery Coding standards and best practices

      I don't know where I saw this article about jQuery Coded articles , It's practical , It just happened that I was studying jQuery Basic knowledge of , Today open my favorite to translate , The original English is not difficult , But the content is practical , Maybe a great God has translated it , Let's look at the essence. . ...

    2. Radar Installation classification : POJ 2015-06-15 19:54 8 Human reading Comment on (0) Collection

      Radar Installation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 60120   Accepted: 13 ...

    3. ltt.js

      var dailyBox = $('.daily-box-office'), curDate = new Date(), curYear = curDate.getFullYear(), curMon ...

    4. iOS Achieve ground glass effect

      Apple is in iOS7.0 after , Many system interfaces use ground glass effects , Increased the beauty of the interface , For example, the notification center interface below ; But its iOS7.0 Of SDK It is not provided for developers to achieve ground glass effect API, So a lot of people are through someone else ...

    5. winform datagridview Add all checkbox Prompt when : Cannot set selected or selected It's not a watch Table Of DataColumn Neither DataRelation.

      In the project , You need multiple choice , So in datagridview Added a column DataGridViewCheckBoxColumn In giving datagridview After binding the dataset , When operating on select all , It's always a mistake , newspaper ...

    6. RHEL6 Delete software RAID

      Stop using RAID: 1.umount raid The partition used by the hard disk on the group If you use raid groups creating vg, Need to be deleted or deactivated VG 2. stop it raid service mdadm -S /dev/md0 3. eliminate MBR # md ...

    7. git &amp;&amp; gitlab Use

      Installation skipped Use Public key based authentication login , It is convenient to control the user's authority useradd -s /usr/bin/git-shell testgit # Create a user Or directly useradd testgit Then go to / ...

    8. Linux Virtual machine installation and environment construction

      1. download centos, Address : Choose... When downloading DVD ISO 2. Use VMware Workstation Installation . 3. Virtual machine network configuration     ...

    9. Mybatis abnormal There is no getter for property named &#39;XXX&#39; in &#39;class java.lang.String&#39;

      1. When you join in  string Type ( Include java.lang.String.)  We use #{xxx} Introduce parameters . Would throw exceptions There is no getter for property named 'XX ...

    10. s11.1 lsof: View files opened by the process

      Functional specifications lsof Full name list open files, That is to list the open files in the system , adopt lsof command , You can find the corresponding process information according to the file , You can also find the file opened by the process according to the process information . [ Grammar format ] l ...