使用
JK整合,下载mod_jk-1.2.30-httpd-2.2.3.so放到apache的module目录下更名为mod_jk.so
JK 的配置最关键的有三个文件,分别是
httpd.conf
Apache 服务器的配置文件,用来加载 JK 模块以及指定 JK 配置文件信息
workers.properties
到 Tomcat 服务器的连接定义文件
uriworkermap.properties
URI 映射文件,用来指定哪些 URL 由 Tomcat 处理,你也可以直接在 httpd.conf 中配置这些 URI,但是独立这些配置的好处是 JK 模块会定期更新该文件的内容,使得我们修改配置的时候无需重新启动 Apache 服务器。
其中第二、三个配置文件名都可以自定义。下面是一个典型的 httpd.conf 对 JK 的配置
可以新建一个文件extra/httpd-jk.conf来设置jk然后在httpd中包含它,使得httpd.conf简洁
httpd.conf
Include conf/extra/httpd-jk.conf
extra/httpd-jk.conf
#------------------------
# 加载 mod_jk 模块
LoadModule jk_module modules/mod_jk.so
#------------------------
# Configure mod_jk
JkWorkersFile conf/workers.properties
JkMountFile conf/uriworkermap.properties
JkLogFile logs/mod_jk.log JkLogLevel warn
#------------------------------------------------
#设置虚拟目录 用于访问tomcat webapp下的静态文件
Alias /sjsw "D:/SHMC_BMS_Project/SJSW/WebContent"
<Directory "D:/SHMC_BMS_Project/SJSW/WebContent">
AllowOverride None
Options all
Order allow,deny
Allow from all
</Directory>
接下来我们在 Apache 的 conf 目录下新建两个文件分别是 workers.properties、uriworkermap.properties。这两个文件的内容大概如下
workers.properties
#------------------------
# workers.properties
# list the workers by name
worker.list=s1,status
#设置负载平衡多服务器
#worker.list=DLOG4J, status
# localhost server 1
# ------------------------
#port和tomcat server.xml中的保持一致 <!-- Define an AJP 1.3 Connector on port 8009 --> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
worker.s1.port=8009
worker.s1.host=localhost
worker.s1.type=ajp13
# localhost server 2
# ------------------------
#worker.s2.port=8009
#worker.s2.host=localhost
#worker.s2.type=ajp13
#worker.s2.stopped=1
#worker.DLOG4J.type=lb
#worker.retries=3
#worker.DLOG4J.balanced_workers=s1,s2
#worker.DLOG4J.sticky_session=1
#查看jkstatus
worker.status.type=status
uriworkermap.properties
#/*=DLOG4J
/*=s1
/jkstatus=status
!/*.gif=s1
!/*.jpg=s1
!/*.png=s1
!/*.css=s1
!/*.js=s1
!/*.htm=s1
!/*.html=s1