TOMCAT 集成 APACHE
1 准备
下载软件
1.1 Apache
文件名:
apache_2.2.11-win32-x86-openssl-0.9.8i.msi
下载地址:
http://apache.freelamp.com/httpd/binaries/win32/apache_2.2.11-win32-x86-no_ssl.msi
1.2 Tomcat
文件名:
apache-tomcat-6.0.18.zip
下载地址:
http://labs.xiaonei.com/apache-mirror/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.zip
1.3 mod_jk
文件名:
mod_jk-1.2.27-httpd-2.2.10.so
下载地址:
http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.27/mod_jk-1.2.27-httpd-2.2.10.so
2 安装 apache
假设安装目录是: C:\Apache2.2
端口默认 80
3 安装 tomcat
假设安装路径是: C:\apache-tomcat-6.0.18
端口默认 8080
4 配置 apache
4.1 拷贝文件 mod_jk-1.2.27-httpd-2.2.10.so
拷贝文件 mod_jk-1.2.27-httpd-2.2.10.so 到 C:\Apache2.2\modules 。并且改名为 mod_jk.so
4.2 建立文件 workers.properties
建立文件 C:\Apache2.2\conf\ workers.properties
worker.list=worker1 worker.worker1.type=ajp13 worker.worker1.host=localhost worker.worker1.port=8009 |
4.3 修改文件 httpd.conf
找到 C:\Apache2.2\conf\ httpd.conf 文件。
修改原有 DocumentRoot 设置
# DocumentRoot "C:/Apache2.2/htdocs" DocumentRoot "C:/apache-tomcat-6.0.18/webapps" |
接着在末尾添加如下内容
<Directory "C:/apache-tomcat-6.0.18/webapps/my"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory>
# Load mod_jk module # Update this path to match your modules location LoadModule jk_module modules/mod_jk.so # Declare the module for <IfModule directive> (remove this line on Apache 2.x) # AddModule mod_jk.c # Where to find workers.properties # Update this path to match your conf directory location (put workers.properties next to httpd.conf) JkWorkersFile conf/workers.properties # Where to put jk shared memory # Update this path to match your local state directory or logs directory JkShmFile logs/mod_jk.shm # Where to put jk logs # Update this path to match your logs directory location (put mod_jk.log next to access_log) JkLogFile logs/mod_jk.log # Set the jk log level [debug/error/info] JkLogLevel debug # Select the timestamp log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " # Send everything for context /examples to worker named worker1 (ajp13) JkMount /my/servlet/* worker1 |
相关的官方说明可以在这里找到。
http://tomcat.apache.org/connectors-doc/generic_howto/quick.html
5 配置 tomcat
确认 C:\apache-tomcat-6.0.18\conf\server.xml 配置如下:(默认就是这样一般不需要改动)
<!-- Define an AJP 1.3 Connector on port 8009 --> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> |
6 添加一个 servlet
比如 HelloWorldServlet
确认从这个地址能访问到这个 servlet
http://127.0.0.1:8080/my/HelloWorldServlet
7 重启 tomcat
应该看到如下信息:
2009-3-13 20:54:14 org.apache.jk.common.ChannelSocket init 信息 : JK: ajp13 listening on /0.0.0.0:8009 |
8 重启 apache
如果如下地址也能访问。说明 tomcat 和 apache 整合成功
http://127.0.0.1/my/HelloWorldServlet