Objective:
The benefits of using Apache
Tomcat, in addition to supporting Java servlet/jsp, can also be used as a Web server, but in the static HTML files , picture files , such as parsing efficiency is not as efficient as the Apache httpd execution. Servers that apply Tomcat if the site has a large number of visits, system resource consumption will increase significantly,
Apache and Tomcat working processes:
Apache as the primary server running, when the monitor has a JSP or servlet request, the request to the Tomcat server, by the Tomcat server to resolve, sent back to Apache, and then sent back to the user by Apache. There are two listening ports in Tomcat, one for 8080 for Web services, and one for 8009 for listening to requests from Apache. When Apache receives a JSP or servlet request, it sends a request to Tomcat's 8009 port, which is then returned to Apache, which is returned to the customer by Apache.
Demand:
Page A picture request-"Apache Fetch request-" forwarded to the Tomcat Servlet->servlet performs the decompression program->servlet output to the page.
preparatory work:
Jdk:d:\program files\java\jdk1.6.0_18
apache2.2:d:\apache2.2
tomcat:d:\tomcat-6.0.33
Download the mod_jk-apache-2.2.4.so file into the Apache modules directory
Configure Tomcat:
(1), in the D:\tomcat-6.0.33\conf directory to create workers.properties files edited as follows:
#让mod_jk模块知道Tomcat的位置
workers.tomcat_home=d:\tomcat-6.0.33
#让mod_jk模块知道jre的位置
workers.java_home=d : \program Files\java\jdk1.6.0_18
#模块版本
ps=\
worker.list=ajp13
#工作端口, if not occupied without modification
worker.ajp13.port=8009
#本机, if the above Apache host is not localhost, make the corresponding modification
worker.ajp13.host=localhost
#类型
Worker.ajp13.type=ajp13
#负责均衡因子
worker.ajp13.lbfactor=1
(2), configure the Server.xml files under the Tomcat directory, add in
<context path= "" docbase= "D:\mapbar\data\www\image" reloadable= "true" crosscontext= "true"/>
D:\mapbar\data\www\image directory for picture tar Package store path
Configure Apache:
(1), edit httpd.conf, modify DocumentRoot for:
DocumentRoot "D:\mapbar\data\www\image"
D:\mapbar\data\www\image path stored in the picture tar file
(2) Edit httpd.conf, append later
#设置Apache与Tomcat之间的连接, let Apache encounter jsp,gif,png,servlet files, in the background to Tomcat to deal with
#加载mod_jk文件
LoadModule jk_module modules/mod_jk-apache-2.2.4.so
#加载跳转文件
LoadModule rewrite_module modules/mod_rewrite.so
# Specifies Tomcat Listener profile address
jkworkersfile "d:/tomcat-6.0.33/conf/workers.properties"
#指定日志存放位置
jklogfile d:/ Tomcat-6.0.33/logs/imges.log "
jkloglevel info
#重定向
rewriteengine on
rewriterule ^[/s/s]*/ maplite/mapbank/mapbar/(. *) $ http://localhost/imagetar/readtarimage/maplite/mapbank/mapbar/$1 [L]
# Only the URL of the picture request is sent to Tomcat for processing
#JKMount/*.gif ajp13
jkmount/*.png ajp13
#JkMount/servlet/* ajp13
# Allow Apache to support JSP transfer for Tomcat parsing
Jkmount/*.jsp ajp13
Pay attention to the writing of Rewriterule
Format: Mode (pattern) jump [optional]
(pattern) is a regular formula that matches the current URL.
For example: the requested Url:http://localhost/maplite/mapbank/mapbar/7/58_25/3_0.png
Apache will automatically jump to http://localhost/ImageTar/ReadTarImage/maplite/mapbank/mapbar/7/58_25/3_0.png. Imagetar is the project name and Readtarimage is a servlet.
In the Web.xml file <url-pattern>*.png</url-pattern> configured the *.png wildcard character so that it goes into the servlet.
After the modification completes this, again executes D:\Apache2.2\bin\httpd-t if sees "Syntax OK", indicated that all your configuration is correct