配置参考 http://blog.csdn.net/hobbypei/article/details/8234933
1.下载相关软件
1)下载apache
http://mirror.bjtu.edu.cn/apache/httpd/binaries/win32/
2)下载 tomcat 6
3)下载 mode_jk.so
2.设置配置文件
1)修改tomcat 配置文件/conf/server.xml,修改tomcat 访问协议为“HTTP/1.1” 的端口及访问协议“AJP/1.3” 的端口
<Connector port="8088" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
<Connector port="8019" protocol="AJP/1.3" redirectPort="8443" />
2)在apache的目录/module下/添加mod_jk.so
3)在apache的目录/conf 下添加workers.properties ,
内容如下:
#指定tomcat安装目录
workers.tomcat_home="E:\cpcServer\apache-tomcat-6"
#指定javahome 让mod_jk知道jkd目录
workers.java_home="E:\cpcServer\Java\jdk1.6.0_11"
ps=\
#这是关键,名字要和配置httpd.conf和httpd-vhosts.conf 名字一致。
worker.list=ajp13
#工作端口,tomcat的jk监听端口
worker.ajp13.port=8019
#tomcat所在机器,如果不在本机则设置ip
worker.ajp13.host=localhost
#类型不能改
worker.ajp13.type=ajp13
#负责平衡因子
worker.ajp13.lbfactor=1
4)修改apache目录/conf下httpd.conf 文件
修改监听端口:Listen 8080
把module中的
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so
Include conf/extra/httpd-vhosts.conf
的屏蔽 打开;
添加:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile "E:\cpcServer\apache_cpc\Apache2.2\conf\workers.properties"
JkLogFile "E:\cpcServer\apache_cpc\Apache2.2\logs\mod_jk.log"
JkLogLevel info
<Directory "E:/cpcServer/app">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
修改项目根目录:
DocumentRoot "E:/cpcServer/app"
5)修改apache目录/conf/extra/httpd-vhost.conf,
内容如下:
NameVirtualHost *:8080
<VirtualHost *:8080>
ServerAdmin cpc@cpc.com
DocumentRoot "E:/cpcServer/app"
JkMount /*.action ajp13
JkMount /*.jsp ajp13
#JkMount /*/messagebroker/amf ajp13
#JkMount /servlet/* ajp13
#JKMount /MoreSearch ajp13
#JkMount /* ajp13
DirectoryIndex info.htm index.htm index.html index.jsp
</VirtualHost>
备注:
1.如何设置缓存。
#缓存配置设置
<IfModule mod_cache.c>
#默认缓存有效期 秒
CacheDefaultExpire 3600
CacheMaxExpire 86400
CacheLastModifiedFactor 0.1
#禁止缓存某些特定的URL
#CacheDisable /local_files
#使用特定的存储类型缓存某些特定的URL
#CacheEnable mem /manual
CacheEnable fd /*/images
CacheEnable disk /
<IfModule mod_mem_cache.c>
CacheEnable mem /
MCacheSize 8192
# MCacheMaxObjectCount 10000
MCacheMinObjectSize 1
# MCacheMaxObjectSize 51200
#MCacheRemovalAlgorithm LRU
</IfModule>
</IfModule>
#浏览器缓存配置设置
#<IfModule expires_module>
# ExpiresActive On
# ExpiresByType text/html "access plus 15 days"
# ExpiresDefault "access plus 1 month"
#</IfModule>
# 解开.
#LoadModule expires_module modules/mod_expires.so
#浏览器缓存配置设置
#<IfModule expires_module>
#ExpiresActive On
#ExpiresByType text/html "access plus 15 days"
#ExpiresByType text/css "access plus 15 days"
#ExpiresByType application/javascript "access plus 15 days"
#ExpiresDefault "access plus 1 month"
#ExpiresDefault A86400
#ExpiresByType text/plain A86400
#ExpiresByType text/html A86400
#ExpiresByType image/x-ico A259200
#ExpiresByType text/css A604800
#ExpiresByType image/gif A2592000
#ExpiresByType image/png A2592000
#ExpiresByType image/jpeg A2592000
#ExpiresByType application/pdf A2592000
#ExpiresByType application/javascript A2592000
#ExpiresByType application/x-shockwave-flash A2592000
#ExpiresByType video/x-flv A2592000
#ExpiresByType application/x-javascript A2592000
#</IfModule>
# 解开.
#LoadModule deflate_module modules/mod_deflate.so
#LoadModule headers_module modules/mod_headers.so
#压缩文件成gzip (gzip 支持IE、火狐、网景、等浏览器)
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:pdf|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary
AddOutputFilterByType DEFLATE text/*
AddOutputFilterByType DEFLATE application/ms* application/vnd* application/postscript application/javascript application/x-javascript
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
2.#解决Request Entity Too Large问题
在workers.properties文件中添加下面内容
worker.worker_cpc.max_packet_size=65536
在tomcat/conf/server.xml 文件中添加
<Connector port="8039" protocol="AJP/1.3" redirectPort="8443" packetSize="65536" URIEncoding="UTF-8"/>