Tomcat Server Configuration Details

Posted by Altairzq on Sat, 07 Sep 2019 08:32:24 +0200

Tomcat server is a free open source web application server, which belongs to lightweight application server. It is widely used in small and medium-sized systems and occasions where concurrent users are not very many. It is the first choice for developing and testing JSP programs. Generally speaking, Tomcat, like apache or Nginx web servers, has the ability to process HTML pages. However, because its ability to process static pages is far inferior to apache or Nginx, Tomcat usually runs as a servlet and JSP container, running in the back end alone.

For the deployment process and application environment of Tomcat server, please refer to blog https://blog.51cto.com/14227204/2436201.

About the role of Tomcat's configuration file and related instructions:
JDK must be installed before Tomcat is installed. JDK is a free Java language software development kit provided by sun Company, which includes Java Virtual Machine (JVM). The compiled Java source program can be compiled to form Java bytecode. As long as JDK is installed, these code files can be interpreted by JVM, thus ensuring the cross-platform nature of Java.

In terms of platform compatibility, JDK, as a Java virtual machine that interprets bytecode files and invokes API of operating system to implement corresponding functions, is closely related to the type of operating system and the number of platforms, so there are different versions, and Tomcat also has these characteristics. By default, JDK has been installed and can be used as follows Command to check whether JDK is installed:

[root@localhost ~]# java -version    #Check whether the JDK is installed or not. If not, you need to install it yourself.
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)

Main catalogue descriptions:

[root@localhost ~]# cd /usr/local/tomcat8/         #Switch to Tomcat directory
[root@localhost tomcat8]# ll                   #View everything in the catalog
//Total dosage 92
drwxr-x--- 2 root root  4096 6 February 2220:08 bin             
#Store script files for starting and closing Tomcat on Windows or Linux platforms
drwx------ 2 root root   238 6 February 22, 2017 conf
#Store various global configuration files for Tomcat server, the most important of which are server.xml and web.xml
drwxr-x--- 2 root root  4096 6 February 2220:08 lib
#Store the library files needed for Tomcat to run
-rw-r----- 1 root root 57092 6 February 22, 2017 LICENSE
drwxr-x--- 2 root root     6 6 February 22, 2017 logs
#Store the log file when Tomcat executes
-rw-r----- 1 root root  1723 6 February 22, 2017 NOTICE
-rw-r----- 1 root root  7064 6 February 22, 2017 RELEASE-NOTES
-rw-r----- 1 root root 15946 6 February 22, 2017 RUNNING.txt
drwxr-x--- 2 root root    30 6 February 2220:08 temp
drwxr-x--- 7 root root    81 6 February 22, 2017 webapps
#Tomcat's main web publishing directory (including application examples).
drwxr-x--- 2 root root     6 6 February 22, 2017 work
#Store the class file generated by JSP compilation.

Configuration file description:

[root@localhost tomcat8]# ll conf      #View the contents in the conf directory
//Total dosage 224
-rw------- 1 root root  13816 6 February 22, 2017 catalina.policy              #Permission Control Profile
-rw------- 1 root root   7376 6 February 22, 2017 catalina.properties        #Tomcat property profile
-rw------- 1 root root   1338 6 February 22, 2017 context.xml                   #Context Profile
-rw------- 1 root root   1149 6 February 22, 2017 jaspic-providers.xml
-rw------- 1 root root   2358 6 February 22, 2017 jaspic-providers.xsd
-rw------- 1 root root   3622 6 February 22, 2017 logging.properties         #log-related configuration files
-rw------- 1 root root   7511 6 February 22, 2017 server.xml                     #Master Profile
-rw------- 1 root root   2164 6 February 22, 2017 tomcat-users.xml          #manager-gui Management Profile
#Tomcat provides a manager management interface by default after installation, and access can be opened by configuring the file.
-rw------- 1 root root   2633 6 February 22, 2017 tomcat-users.xsd
-rw------- 1 root root 168251 6 February 22, 2017 web.xml

Tomcat Master Profile Description:
server.xml is the main configuration file of Tomcat. By configuring this file, Tomcat can modify its startup port, website directory, virtual host, https and other important functions.

The whole server.xml consists of the following structures: <Server>, <Service>, <Connector/><Engine>, <Host>, <Context>, </Context> </Host> </Engine> </Service> and </Server>.

The following is part of the default installation of server.xml file:

[root@localhost tomcat8]# vim conf/server.xml
<?xml version="1.0" encoding="UTF-8"?>
............                                  #Omit part of content
<Server port="8005" shutdown="SHUTDOWN">                
#Tomcat closes the port. By default, it is only open to the local address. It can be accessed locally through Telnet 127.0.0.1 8005.
#Close Tomcat
............                                  #Omit part of content
 <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
#The default port number of Tomcat startup is 8080, which can be changed as needed.
............                                  #Omit part of content
 <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
#The default port number when Tomcat starts the AJP 1.3 connector can be changed as needed
............                                  #Omit part of content
#Here is Tomcat's configuration and log configuration when defining a virtual host
<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 "%r" %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>

Component description of Tomcat server:
Server

The server element represents the entire CatAlina servlet container.

Service

Service is a collection consisting of one or more Connectors and an Engine (responsible for handling all customer requests received by Connectors).

Connector

A Connector listens to a customer request on a specified port and handles the request to Engine to process, gets a response from Engine and returns it to the customer.

 Tomcat has two typical Connector s: one listens directly to http requests from browser and the other listens to requests from other web servers.

 Coyote http/1.1 Connector listens for http requests from the client browser at port 8080.

 Coyote JK2 Connector listens for servlet/jsp proxy requests from other text server s (Apache) at port 8009.

Engine:

Under Engine, you can configure multiple virtual host s, each of which has a domain name.

When Engine receives a request, it matches the request to a Host, and then handles the request to the host.

Engine has a default virtual host, which handles requests that cannot be matched to any host.

Host

Host represents a virtual Host, each of which matches a domain name Domain Name.

One or more web apps can be deployed under each virtual host. Each web app corresponds to a Context and has a Context path.

When the host receives a request, the request is matched to a Context, and then the request is handed over to the Context for processing. The matching method is "longest matching", so a contexts with path="" will become the default Context of the Host.
All requests that cannot match the path names of other Contexts will eventually match the default Context.

Context

A Context corresponds to a web application, and a web application consists of one or more servlet s.

Topics: Linux Tomcat xml JDK Java