A.軟件准備
j2sdk-1_4_2_04-windows-i586-p
Apache2.0.52
jakarta-tomcat-5.0.28
mod_jk-1.2.14-apache-2.0.54
B.安裝
apache 安裝到C:\Apache\Apache2
tomcat 安裝到c:\tomcat
jdk 安裝到d:\j2sdk1.4.2_04
C.環境變量設置
安裝j2sdk以後,需要配置一下環境變量,在我的電腦->屬性->高級->環境變量->系統變量中添加以下環境變量(假定你的j2sdk安裝在c:\j2sdk1.4.2):
JAVA_HOME=c:\j2sdk1.4.2
classpath=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;(.;一定不能少,因為它代表當前路徑)
path=%JAVA_HOME%\bin
安裝Tomcat後,在我的電腦->屬性->高級->環境變量->系統變量中添加以下環境變量(假定你的tomcat安裝在c:\tomcat):
CATALINA_HOME=c:\tomcat;
CATALINA_BASE=c:\tomcat;
d:配置
apache配置:
1、mod_jk.so(不是這個名字的話請重命名為此名字)復制到modules目錄下;
2、編輯一個workers.properties文件,放在Apache的conf目錄下,添加如下內容
[shm]
file=C:/Apache/Apache2/logs/shm.file #根據實際安裝的目錄
size=1048576
#The socket channel,最關鍵的部分,定義與Apache的交互IP和端口
[channel.socket:localhost:8009]
port=8009
host=localhost
#define the worker,應該是定義與Apache的通道,用的是ajp13引擎指向8009端口
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009
#uri mapping,對servlet和jsp的映射,這裡還可以加入do文件等的映射,注意用的是ajp13引擎
[uri:/*]
[uri:/*.jsp]
worker=ajp13:localhost:8009
3、對於httpd.conf文件的處理,是最關鍵的一步,末尾添加內容如下:
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile conf/workers.properties
# Where to put jk logs
JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat “[%a %b %d %H:%M:%S %Y] ”
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat “%w %V %T”
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot “c:/Tomcat/webapps/ROOT”
ServerName 127.0.0.1
ErrorLog logs/k99k.com-error_log
CustomLog logs/k99k.com-access_log common
DirectoryIndex index.html index.htm index.jsp Read
# Send servlet用ajp13引擎,對於像/*這樣的請求
JkMount /* ajp13
# Send JSPs用ajp13引擎,對於像/*.jsp這樣的請求
JkMount /*.jsp ajp13
</VirtualHost>
Tomcat配置
1、在Tomcat的conf目錄中,已經有了jk2.properties文件,把它打開,覆蓋文件內容為:
## THIS FILE MAY BE OVERRIDEN AT RUNTIME. MAKE SURE TOMCAT IS STOPED
## WHEN YOU EDIT THE FILE.
## COMMENTS WILL BE _LOST_
## DOCUMENTATION OF THE FORMAT IN JkMain javadoc.
# Set the desired handler list
handler.list=apr,request,channelSocket
#
# Override the default port for the socketChannel
channelSocket.port=8019
# Default:
# channelUnix.file=${jkHome}/work/jk2.socket
# Just to check if the the config is working
# shm.file=${jkHome}/work/jk2.shm
# In order to enable jni use any channelJni directive
# channelJni.disabled = 0
# And one of the following directives:
重啟tomcat和apache,輸入http://localhost:8080 和http://localhost都出現tomcat歡迎頁面,則表示配置成功!