I have checked a lot of information on the Internet. I want to know how to integrate Apache and tomcat so that httpd of Apache is responsible for static content and Tomcat is responsible for dynamic content.
References:
Http://tomcat.apache.org/connectors-doc/generic_howto/quick.html
Http://code-worker.javaeye.com/blog/246993
Http://www.qqread.com/php/n652282101.html
Http://tomcat.apache.org/connectors-doc/reference/workers.html
I tried it myself and recorded the specific process for future reference.
1. install Apache HTTP Server, tomcat, and Tomcat Connector (jk module)
- Apache httpd: Download the Apache HTTP Server 2.2.15 installation version from the Internet (it seems that no compression version is installed ). During installation, you can choose to install it as a system service or start it manually each time. I chose the latter for testing, but the latter will listen to port 8080 by default. Be sure not to conflict with Tomcat's default port 8080. This item can be modified later in the configuration file.
- Tomcat: You can choose to install the free compressed version (I use version 6.0.18), which is very convenient and can be registered as a system service.
- JK module: It is located in the modules directory under the composer HTTP Server installation directory.
2. Create the workers. properties file.
See http://tomcat.apache.org/connectors-doc/generic_howto/quick.html
This worker. properties can be placed under any directory, and I put it directly under the installation directory of Apache HTTP server.
# Specify the tomcat installation path for the mod_jk Module
Workers. Maid = D:/devsoft/Apache-Tomcat-6.0.18
# Specify the JDK installation path for the mod_jk Module
Workers. java_home = C:/program files/Java/jdk1.6.0 _ 20
# Add a worker to the worker list
Worker. List = worker1
# Set parameters for worker1
# Working port: Tomcat's default connector listening port. You can view the Port = "8009" in Tomcat server. xml"
Worker. worker1.port = 8009
# Tomcat machine. If it is installed on a machine different from Apache, you need to set the IP address
Worker. worker1.host = localhost
# Worker type. The allowed values are ajp13, ajp14, LB, and status. ajp13 is the preferred method for mod_jk to connect webserver and Tomcat (that is, socket is used as the communication channel)
Worker. worker1.type = ajp13
# Load Balancing Factor
Worker. worker1.lbfactor = 1
Note: The worker name in worker. List should correspond to jkmount In the httpd. conf configuration file of Apache HTTP Server (detailed later ).
3. Modify the httpd. conf configuration file of Apache HTTP Server
Modify the httpd. conf file in the conf directory of the Apache HTTP Server installation directory:
# Load the mod_jk module. Pay attention to the module File Path.
Loadmodule jk_module modules/mod_jk.so
# Declare the location of the workers. properties File
Jkworkersfile "C:/program files/Apache Software Foundation/apache2.2/workers. properties"
# Declare the location of the mod_jk Log File
Jklogfile "C:/program files/Apache Software Foundation/apache2.2/logs/mod_jk.log"
# Declare the Log Level of mod_jk (optional)
Jkloglevel info
# Declare the timestamp format of the mod_jk log (optional)
Jklogstampformat "[% A % B % d % H: % m: % S % Y]"
# Allocate requests of the/*. Action and/*. jsp types to Tomcat, And the other types are processed by the Apache HTTP Server.
# Note that worker1 after jkmount corresponds to the name of worker in worker. List in worker. properties.
Jkmount/*. Action worker1
Jkmount/*. jsp worker1
4. Modify directoryroot
Most of the articles on the Internet are finished after they are written above. The dynamic content is handed over to Tomcat, but the static content allocation still requires setting the httpd. conf file.
Find the DocumentRoot "C:/program files/Apache Software Foundation/apache2.2/htdocs" line and replace the value with the path of the Web application:
DocumentRoot "D:/devsoft/Apache-Tomcat-6.0.18/webapps"
Find the <directory "C:/program files/Apache Software Foundation/apache2.2/htdocs"> line and replace the value with the path of the Web application:
<Directory "D:/devsoft/Apache-Tomcat-6.0.18/webapps">
At this point, requests for dynamic and static content are allocated.