The integration of the Tomcat Development technology with the HTTP server

Source: Internet
Author: User

Tomcat's main function is to provide a servlet/jsp container, although it can also be used as a standalone Java Web server, which is less capable of processing static resources (such as HTML files or image files) and providing Web server governance capabilities than other professional HTTP servers , such as IIS and Apache servers.
  
So in practical applications, Tomcat is often integrated with other HTTP servers. For HTTP servers that do not support servlet/jsp, the servlet/jsp component can be run through the Tomcat server.
  
When Tomcat is integrated with other HTTP servers, the Tomcat server's working mode is typically the out-of-process servlet container, and the Tomcat server communicates with the other HTTP servers through specialized plug-ins. The concept of a Tomcat server's working mode can be found in section 1.4 of this book.
  
This chapter begins with a discussion of the general principles of Tomcat and HTTP server integration, and then describes the specific steps of Tomcat integration with Apache and IIS.
  
22.1 Tomcat and HTTP Server integration principles
  
The tomcat server connects to the client through the Connector Connector component, the connector component is responsible for receiving the customer's request, and the results of the Tomcat server's response are sent to the customer. By default, Tomcat configures two types of connectors in Server.xml:
  
<!--Define a non-ssl Coyote http/1.1
Connector on port 8080--
<connector port= "8080"
Maxthreads= "150"
Minsparethreads= "25"
maxsparethreads= "75"
Enablelookups= "false"
Redirectport= "8443"
acceptcount= "100"
debug= "0"
connectiontimeout= "20000"
Disableuploadtimeout= "true"/>
  
<!--Define a COYOTE/JK2 AJP 1.3
Connector on port 8009--
<connector port= "8009"
Enablelookups= "false"
Redirectport= "8443" debug= "0"
Protocol= "ajp/1.3"/>
  
The first connector listens on port 8080 and is responsible for establishing an HTTP connection. This connector is used when accessing a web App for a tomcat server through a browser.
  
The second connector listens on port 8009 and is responsible for establishing connections to other HTTP servers. When you integrate Tomcat with other HTTP servers, you need to use this connector.
  
The Web client accesses the JSP component on the Tomcat server in two ways, as shown in 22-1.
   
Figure 22-1 Two ways a Web client accesses a JSP component on a tomcat server
  
In Figure 22-1, Web Client 1 directly accesses the JSP component on the Tomcat server, and the URL he accesses is http://localhost:8080/index.jsp. Web Client 2 accesses the JSP components on the Tomcat server through an HTTP server. Assuming that the HTTP server uses the HTTP port as the default port of 80, Web Client 2 accesses the URL http://localhost:80/index.jsp or http://localhost/index.jsp.
  
Below, describes how Tomcat communicates with the HTTP server.
  
22.1.1 JK Plugin
  
Tomcat provides a dedicated JK plugin to be responsible for the communication between Tomcat and the HTTP server. JK Plugins should be placed on each other's HTTP server. When the HTTP server receives a client request, it filters the URL,JK plugin through the JK plugin to determine whether to forward the client request to the Tomcat server for processing based on the pre-configured URL mapping information.
  
Assuming that all "/*.jsp" URLs are handled by the Tomcat server in the pre-configured URL mapping information, in the example in Figure 22-1, the JK plugin forwards the client request to the Tomcat server, The Tomcat server then runs the index.jsp, then passes the response to the HTTP server, and the HTTP server transmits the response to the Web Client 2.
  
For different HTTP servers, Tomcat provides a different implementation module for JK Plugins. This chapter will use the following JK plugins:
  
Integration with Apache HTTP server under Windows: Mod_jk_2.0.46.dll
  
Integration with Apache HTTP server under Linux (Redhet): mod_jk.so-ap2.0.46-rh72. 46-rh72
  
Integration with IIS server: Isapi_redirect.dll
  
22.1.2 AJP Protocol
  
AJP is a protocol customized for the communication between Tomcat and the HTTP server, providing high communication speed and efficiency. In configuring Tomcat and HTTP server integration, the reader does not have to care about the details of the AJP protocol. You can also refer to the website for AJP knowledge:
  
Http://jakarta.apache.org/builds/jakarta-tomcat-connectors/jk2/doc/common/AJPv13.html
  
22.2 integration with Apache server under Windows Tomcat
  
Apache HTTP server is an Apache software organization provides open source software, it is a very good professional Web server, for network administrator provides a variety of web governance features, including directory index, directory aliases, content negotiation, configurable HTTP error reporting, setuid execution of CGI programs, child process resource governance, server-side image mapping, rewrite URLs, url spelling checks, and online manuals.
  
The Apache HTTP server itself does not provide a servlet/jsp container. Therefore, in practical applications, the integration of Tomcat with Apache can create a commercially viable web platform with practical value. The software required for the integration of Tomcat and Apache servers under Windows nt/2000 is described in table 22-1.
  
Table 22-1 software required for Tomcat integration with Apache server in Windows nt/2000
   
1. Install Apache HTTP Server
  
When you run Apache_2.0.47-win32-x86-no_ssl.msi, you start the Apache HTTP Server installation program, as long as the default settings are installed. If the installation succeeds, the Apache HTTP service will automatically be added to Windows, as shown in 22-2.
   
Figure 22-2 The Apache service added to the Windows service
  
Assuming that the root directory of Apache is, there is a configuration file httpd.conf under its conf subdirectory. If Apache is installed natively and uses the default port of 80 as the HTTP port, you will see the following properties in the httpd.conf file:
  
Listen 80
ServerName localhost:80
  
In the operating system "start" → "program" → "Apache HTTP server 2.0.47" → "Control Apache Server" menu, provides the restart (Restart), Start (start) and close (Stop) the submenu of the Apache server.
  
You should ensure that port 80 is not in use or the Apache server will not start. After the Apache server is started, you can access the Apache test page to determine if the installation was successful. Visit http://localhost, if the page shown in 22-3 shows that Apache has been installed successfully.
   
Figure 22-3 Test Web page for Apache server
  
2. Add JK Plugin to Apache
  
To add JK Plugins to Apache, simply copy the Mod_jk_2.0.46.dll to the/modules directory.
  
3. Create a Workers.properties file
  
The Workers.properties file is used to configure Tomcat information, where it is stored in/conf/workers.properties. The workers.properties file is provided in the Sourcecode/chapter22/windows_apache Directory of the companion CD of this book, and its contents are as follows ("#" followed by the comment information):
  
Workers.tomcat_home=c:\jakarta-tomcat
#让mod_jk模块知道Tomcat
workers.java_home=c:\j2sdk1.4.2
#让mod_jk模块知道j2sdk
ps= #指定文件路径分割符
Worker.list=worker1
worker.worker1.port=8009
#工作端口, no modifications if not occupied
Worker.worker1.host=localhost
#Tomcat服务器的地址
Worker.worker1.type=ajp13
#类型
Worker.worker1.lbfactor=1
#负载平衡因数
  
See table 22-2 for attribute descriptions in the above file.
  
Table 22-2 Properties of the Workers.properties file
   
4, modify the Apache configuration file httpd.conf
  
Open a/conf/httpd.conf file and add the following to the end of it:
  
# Using Mod_jk2.dll to
REDIRECT Dynamic calls to Tomcat
LoadModule Jk_module
Modules\mod_jk_2.0.46.dll
Jkworkersfile
"Conf\workers.properties"
Jklogfile "Logs\mod_jk2.log"
Jkloglevel Debug
Jkmount/*.jsp Worker1
jkmount/helloapp/* Worker1
  
Sourcecode/chapter22/windows_apache/httpd_ on the companion CD of this book The above is provided in the modify.conf file, which instructs the Apache server to load the JK plugin and set the relevant properties for the JK plugin, as described in table 22-3.
  
Table 22-3 related properties of JK Plugins
  
Jkmount is used to specify URL mapping information, "Jkmount/*.jsp worker1" means that the URL in the form "/*.jsp" is handled by the Tomcat server represented by Worker1; "Jkmount/helloapp/* Worker1" The URL that represents access to the HelloApp app is handled by Worker1.
  
5. Test Configuration
  
Reboot the Tomcat server and Apache server to access http://localhost/index.jsp via the browser, if the default home page for Tomcat indicates that the configuration was successful. In addition, if the HelloApp application has been published on the Tomcat server, you can access http://localhost/helloapp/index.htm, and if you return to the Index.htm Web page of the HelloApp application, the configuration is successful.
  
If the configuration is incorrect, you can view the log information generated by the JK plugin, which helps to find the cause of the error. In Apache configuration file httpd.conf, set the log file location to/logs/mod_jk2.log
  
6. Load balancing when Apache integrates with multiple tomcat servers
  
In practical applications, if the site is very large, in order to improve the speed of access, multiple Tomcat servers can be integrated with Apache, allowing them to share the task of running servlet/jsp components. The LoadBalancer (load balancer) of JK Plugins is responsible for load balancing by assigning workloads to these Tomcat servers based on the pre-configured lbfactor (Load Balancing factor) in the Workers.properties file.
  
Assuming Apache and two Tomcat servers are integrated, a Tomcat server and Apache run on the same machine, using a JK port of 8

Excerpted from http://www.studyems.com/network/85500f121604b5b9.html

The integration of the Tomcat Development technology with the HTTP server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.