Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Windows下Tomcat与Apache集成实战:安装Apache、加载JK模块、配置workers.properties、验证JSP转发

編輯:Windows XP 系統介紹

Apache无Servlet/JSP容器,集成Tomcat可构建生产级Web平台。环境:Windows、Apache 2.0.63、Tomcat 6.x。

1. 安装Apache

运行apache_2.0.63-win32-x86-no_ssl.msi默认安装,成功后注册为Windows服务“Apache HTTP Server”。确保80端口未被占用。conf/httpd.conf含Listen 80。通过开始菜单控制启动/停止/重启。

2. 加载JK模块

将mod_jk.so复制到Apachemodules目录。

3. 创建workers.properties

位置:conf/workers.properties,内容:

worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1

worker.list定义Tomcat实例列表(可多个,逗号分隔)。port为AJP端口(默认8009),host为Tomcat地址,type=ajp13固定,lbfactor负载均衡权重。

4. 配置httpd.conf加载JK并转发

在httpd.conf末尾添加:

LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
JkMount /*.jsp worker1
JkMount /helloapp/* worker1

JkMount将.jsp请求及/helloapp/*路径转发给worker1(Tomcat)。

5. 验证

  1. 重启Tomcat、Apache。
  2. 访问https://localhost/index.jsp → 出现Tomcat默认页 = 成功。
  3. 部署测试应用helloapp到Tomcatwebapps,访问https://localhost/helloapp/hello.htm → 正常返回 = 集成成功。
  4. 排错看logs/mod_jk.log。

此架构下Apache处理静态资源、SSL、负载均衡,Tomcat专注动态业务,性能与安全兼得。

Copyright © Windows教程網 All Rights Reserved