Original address: http://blog.csdn.net/gengv/article/details/5739438
Read a lot of information from the Internet, want to know how to integrate Apache and Tomcat, so that Apache httpd responsible for static content, let Tomcat responsible for dynamic content parts.
Reference article:
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 process for future review.
1. Install Apache HTTP server, Tomcat, Tomcat Connector (JK Module) apache Httpd: Download Apache HTTP server from the Internet 2.2.15 installation Version (seemingly no install compression version). You can choose to install it as a system service or to start each time manually. I'm just testing, so I chose the latter, but the latter will listen to port 8080 by default, and be careful not to clash with Tomcat's default port 8080. This item can be modified later in the configuration file. Tomcat: You can choose to install the compact version (I use the 6.0.18 version), very convenient, can be registered as a system service. JK Module: Find binary download from http://tomcat.apache.org/download-connectors.cgi, download current latest version 1.2.30 File Mod_ jk-1.2.30-httpd-2.2.3.so, rename it to mod_jk.so and place it in the modules directory under the Apache Http Server installation directory.
2. Create a new workers.properties file
Refer to: http://tomcat.apache.org/connectors-doc/generic_howto/quick.html
This worker.properties can be placed in any directory, I put it directly in the Apache Http Server installation directory.
# indicates the installation path for Tomcat for the MOD_JK module
workers.tomcat_home=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 individual parameters for Worker1
# work port, Tomcat's default connector listening port, you can view Tomcat in Server.xml with port= "8009"
worker.worker1.port=8009
# tomcat machine, if installed in a different machine than Apache needs to set the IP
Worker.worker1.host=localhost
# type of worker, allowable values are ajp13, AJP14, LB, status, etc. ajp13 is the preferred way to MOD_JK connect webserver and tomcat (i.e. use socket as communication channel)
Worker.worker1.type=ajp13
# load Balancing Factor
Worker.worker1.lbfactor=1
Note: The name of the worker in Worker.list should be the Jkmount in the httpd.conf configuration file corresponding to the Apache Http Server (detailed later).
3. Modify the httpd.conf configuration file for Apache Http server
Modify the httpd.conf file under the Conf directory in the Apache Http Server installation directory:
# Load the MOD_JK module and note the path to the module file
LoadModule Jk_module modules/mod_jk.so
# declaring the location of the Workers.properties file
Jkworkersfile "C:/Program Files/apache software Foundation/apache2.2/workers.properties"
# declares the log file location for MOD_JK
Jklogfile "C:/Program Files/apache software Foundation/apache2.2/logs/mod_jk.log"
# Declare the log level of the MOD_JK (optional)
Jkloglevel Info
# Declare the timestamp format of the MOD_JK log (optional)
Jklogstampformat "[%a%b%d%h:%m:%s%Y]"
#/*.action and/*.jsp types of requests are assigned to Tomcat, and the remaining types have Apache Http server handling themselves
# Note the name of the worker in Worker.list in the Worker.properties file that follows the worker1 of Jkmount
Jkmount/*.action Worker1
Jkmount/*.jsp Worker1
4. Modify Directoryroot
Most of the articles on the Internet are only written to the end of the above, the dynamic content to one of the Tomcat step is completed, but the allocation of static content also need to set the httpd.conf file.
Find the line DocumentRoot "C:/Program Files/apache software Foundation/apache2.2/htdocs" and replace its value with the Web app's path:
DocumentRoot "D:/devsoft/apache-tomcat-6.0.18/webapps"
Find the <directory "C:/Program Files/apache software Foundation/apache2.2/htdocs" > This line and replace its value with the Web app's path:
<directory "D:/devsoft/apache-tomcat-6.0.18/webapps" >
At this point, the dynamic content and static content of the request allocation, is basically complete.