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

SASE vs. SD-WAN: Which one do you pick?

SASE (Secure Access Service Edge) and SD-WAN are ...

Operator workers: What are your plans after receiving your year-end bonus?

It’s the end of the year again. Regardless of whe...

CloudCone: $10.99/year KVM-512MB/20GB/2TB/Los Angeles data center

CloudCone has re-launched the Hashtag 2023 series...

As VR enters its heyday, how will the three major operators plan their layout?

As we all know, VR is a very popular technology n...

Analysis of the global manufacturing IoT market from 2017 to 2024

According to relevant data, the global manufactur...

As containers become more widely used, how should we monitor them?

With the booming development and implementation o...

Google withdraws from 2021 MWC World Mobile Communications Conference

The annual MWC World Mobile Communications Confer...