Tomcat server configuration in detail

Tomcat Server is a free open source web application server, are lightweight application server, not a lot of places that are commonly used in small and medium systems and concurrent users, is the preferred development and testing JSP program. In general, and although the Tomcat web server apache or Nginx such as an HTML page having a processing function, but because of its ability to handle much less apache static page or Nginx, it is generally as a Tomcat servlet and JSP container, operating alone rear end.

Deployment and application environments on Tomcat server, see Bowen: https://blog.51cto.com/14154700/2412180 .

This blog is primarily a chat function and instructions on Tomcat configuration files.

Before you install Tomcat must be installed JDK, JDK is provided free sun's Java language software development kit, which contains the Java Virtual Machine (JVM). Good Java source code can be compiled Java byte code form, as long as they can use to install the JDK JVM interpret the word document, so as to ensure cross-platform written in Java.

Platform compatibility, JDK as interpreted byte code file and accordingly calls the operating system API functions to achieve the corresponding Java Virtual Machine, is closely related to the type of operating system and platform digits, so there are different types of versions, and also Tomcat with these features, JDK is installed by default, the JDK installation can check the following command:

[root@localhost ~]# java -version    #查看JDK是否安装,若没有,自行安装
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)

Tomcat configuration of this blog is not to say, it has been given above of the configuration process Bowen link, if necessary, can refer to the thing I read Bowen, now chat with its profile comments:

1, the main catalog descriptions:

[root@localhost ~]# cd /usr/local/tomcat8/         #切换至Tomcat目录
[root@localhost tomcat8]# ll                   #查看目录下所有内容
总用量 92
drwxr-x--- 2 root root  4096 6月  22 20:08 bin             
#存放Windows或Linux平台上启动和关闭Tomcat的脚本文件
drwx------ 2 root root   238 6月  22 2017 conf
#存放Tomcat服务器的各种全局配置文件,其中最重要的是server.xml和web.xml
drwxr-x--- 2 root root  4096 6月  22 20:08 lib
#存放Tomcat运行需要的库文件
-rw-r----- 1 root root 57092 6月  22 2017 LICENSE
drwxr-x--- 2 root root     6 6月  22 2017 logs
#存放Tomcat执行时的log文件
-rw-r----- 1 root root  1723 6月  22 2017 NOTICE
-rw-r----- 1 root root  7064 6月  22 2017 RELEASE-NOTES
-rw-r----- 1 root root 15946 6月  22 2017 RUNNING.txt
drwxr-x--- 2 root root    30 6月  22 20:08 temp
drwxr-x--- 7 root root    81 6月  22 2017 webapps
#Tomcat的主要web发布目录(包括应用程序示例)。
drwxr-x--- 2 root root     6 6月  22 2017 work
#存放JSP编译后产生的class文件。

2, profile comments:

[root@localhost tomcat8]# ll conf      #查看conf目录下的内容
总用量 224
-rw------- 1 root root  13816 6月  22 2017 catalina.policy              #权限控制配置文件
-rw------- 1 root root   7376 6月  22 2017 catalina.properties        #Tomcat属性配置文件
-rw------- 1 root root   1338 6月  22 2017 context.xml                   #上下文配置文件
-rw------- 1 root root   1149 6月  22 2017 jaspic-providers.xml
-rw------- 1 root root   2358 6月  22 2017 jaspic-providers.xsd
-rw------- 1 root root   3622 6月  22 2017 logging.properties         #日志log相关配置文件
-rw------- 1 root root   7511 6月  22 2017 server.xml                     #主配置文件
-rw------- 1 root root   2164 6月  22 2017 tomcat-users.xml          #manager-gui管理配置文件
#Tomcat安装后默认提供一个manager管理界面,通过配置该文件可以开启访问。
-rw------- 1 root root   2633 6月  22 2017 tomcat-users.xsd
-rw------- 1 root root 168251 6月  22 2017 web.xml

3, Tomcat main profile comments:

server.xml is Tomcat's main configuration file, through the configuration file, you can modify the Tomcat startup port, web directory, web hosting, open https and other important functions.

Server.xml constituted by the entire structure: <Server>, <Service>, <Connector /> <Engine>, <Host>, <Context>, </ Context> </ Host> </ Engine> </ Service> and </ Server>.

The following are the default installation server.xml file section, where <! - -> Comment information content within. # Is a number beginning I wrote:

    [root@localhost tomcat8]# vim conf/server.xml
<?xml version="1.0" encoding="UTF-8"?>
............                                  #省略部分内容
<Server port="8005" shutdown="SHUTDOWN">                
#Tomcat关闭端口,默认只对本机地址开放,可以在本机通过Telnet  127.0.0.1 8005访问,
#对Tomcat进行关闭操作
............                                  #省略部分内容
 <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
#Tomcat启动的默认端口号8080,可以根据需要进行更改。
............                                  #省略部分内容
 <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
#Tomcat启动AJP 1.3连接器时默认的端口号,可以根据需要进行更改
............                                  #省略部分内容
#以下为Tomcat定义虚拟主机时的配置及日志配置
<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>

4, Tomcat server components of description:

①Server

server element represents the entire CatAlina the servlet container.

②Service

Service is a collection: It consists of one or more of the Connector, and a Engine (responsible for handling all client Connector obtained by request) components.

③Connector

A Connector listens for client requests on a designated port, and referred Engine to request to process, get a response from the Engine Department and returned to the client.

 Tomcat有两个典型的Connector,一个直接侦听来自browser的http请求,一个侦听来自其他webserver的请求。

 Coyote  HTTP/1.1  Connector在端口8080处侦听来自客户browser(浏览)的http请求。

 Coyote  JK2   Connector 在端口8009处侦听来自其他文本server(Apache)的servlet/jsp代理请求。

④Engine:

Under Engine can configure multiple virtual hosts virtual host, each virtual host has a domain name.

Engine When a request is obtained, which matches to the request to a Host, then the request to the host for processing.

Engine has a default virtual host, when a request can not be matched to any of a host, the host to the default process.

⑤Host

Host represents a virtual Host (virtual hosts), each virtual host and a network domain Domain Name match.

Under each virtual host may deploy one or more web app, each corresponding to a web app Context, a Context path.

当host获得一个请求时,将把该请求匹配到某个Context上,然后把该请求交给该Context来处理,匹配的方法是“最长匹配”,所以一个path==""的Context将成为该Host的默认Context。

All other requests can not and pathname Context match will be the final match and the default Context.

⑥Context

A Context corresponding to a web application, a web application by one or more of a servlet.

Guess you like

Origin blog.51cto.com/14154700/2412234