Detailed explanation of Tomcat HTTP protocol and AJP protocol

Detailed explanation of Tomcat HTTP protocol and AJP protocol

The main function of Tomcat is to provide a Servlet/JSP container. Although it can also be used as an independent Java Web server, its processing speed for static resources (such as HTML files or image files) and the Web server management functions it provides are not as good as other professional HTTP servers, such as IIS and Apache servers.

Therefore, in practical applications, Tomcat is often integrated with other HTTP servers. For HTTP servers that do not support Servlet/JSP, Servlet/JSP components can be run through Tomcat servers.

When Tomcat is integrated with other HTTP servers, the working mode of the Tomcat server is usually an out-of-process Servlet container, and the Tomcat server communicates with other HTTP servers through special plug-ins.

Tomcat configures two connectors in server.xml.

Related concepts

Two ways for Web clients to access Tomcat servers

  • HTTP Connector: With this connector, Tomcat can become a web server, but it can also handle Servlet and jsp.
  • AJP Connector: The AJP connector can interact with another web container through the AJP protocol.

Connector Configuration

The configuration of the Connector is located in the conf/server.xml file.

1. BIO HTTP/1.1 Connector Configuration

A typical configuration is as follows:

  1. <!--
  2. Code highlighting produced by Actipro CodeHighlighter (freeware)
  3. http://www.CodeHighlighter.com/
  4. -- > connectionTimeout ="20000" redirectPort ="8443"

Some other important properties are as follows:

  • acceptCount: The maximum number of connections to accept connection requests. The default value is 10
  • address : bind IP address, if not bound, any IP address will be bound by default
  • allowTrace : If true, the TRACE HTTP method will be allowed
  • compressibleMimeTypes: each mimeType, separated by commas, such as text/html, text/xml
  • compression: If bandwidth is limited, GZIP compression can be used
  • connectionTimeout : timeout, default is 60000ms (60s)
  • maxKeepAliveRequest : The default value is 100
  • maxThreads: The number of threads of the Connector that processes requests. The default value is 200

If it is SSL configuration, it is as follows:

  1. <!--
  2. Code highlighting produced by Actipro CodeHighlighter (freeware)
  3. http://www.CodeHighlighter.com/
  4. -- > maxThreads = "150"   scheme = "https"   secure = "true"  
  5. clientAuth = "false"   sslProtocol = "TLS"  
  6. address = "0.0.0.0"  
  7. keystoreFile = "E:/java/jonas-full-5.1.0-RC3/conf/keystore.jks"  
  8. keystorePass = "changeit"   />  

Among them, keystoreFile is the certificate location, keystorePass is the certificate password

2. NIO HTTP/1.1 Connector Configuration

  1. <!--
  2. Code highlighting produced by Actipro CodeHighlighter (freeware)
  3. http://www.CodeHighlighter.com/
  4. -- > < Connector   port ="8080" protocol ="org.apache.coyote.http11.Http11NioProtocol"
  5. maxThreads ="150" connectionTimeout ="20000" redirectPort ="8443"

3. Native APR Connector Configuration

ARP is written in C/C++ and optimizes static resources (HTML, images, etc.). So you need to download the local library

tcnative-1.dll and openssl.exe, and place them in the %tomcat%\bin directory.

To configure a Listener in server.xml:

  1. <!--
  2. Code highlighting produced by Actipro CodeHighlighter (freeware)
  3. http://www.CodeHighlighter.com/
  4. -- > <!--APR library loader. Documentation at /docs/apr.html -->   
  5. < Listener   className = "org.apache.catalina.core.AprLifecycleListener"   SSLEngine = "on"   />  
  6. <!-- Configure to use APR connector --》
  7. < Connector   port ="8080" protocol ="org.apache.coyote.http11.Http11AprProtocol"
  8. maxThreads ="150" connectionTimeout ="20000" redirectPort ="8443"

<<:  5G phones are now online. How long can 4G phones last? Can old phones use 5G networks?

>>:  4G speed reduction to make way for 5G? The three major operators collectively denied it. Why do users' perceptions differ from official statements?

Recommend

Different Lianyu Yitong, different SD-WAN+

I am a bit scratching my head. Which word should ...

5G standards usher in new upgrades, driving development into a new stage

Industry development starts with standards. On th...

In-depth study of principles - TCP long connection and heartbeat keep alive

Preface Many Java programmers may only have a thr...

Principles of nine cross-domain implementation methods (full version)

[Original article from 51CTO.com] Cross-domain re...

ColoCrossing: $12/year-1GB/20G SSD/1Gbps unlimited traffic/New York data center

ColoCrossing has released a new VPS promotional p...

ICO was wiped out, is blockchain technology a blessing or a curse?

In the first half of this year, with the skyrocke...

Thoroughly understand cross-domain issues SpringBoot helps you unimpeded

Environment: SpringBoot2.7.16 1. Introduction Cro...

Understanding Internet Protocol Security — IPSec

​IPSec (Internet Protocol Security) is a security...