目的:
整合Apache和Tomcat,使得Java工程和PHP工程都能共用80端口,访问网站时,无需在地址栏中加端口号。
环境说明:
Linux CentOS 32位
Apache 2.2.2
Tomcat 7.0.37
准备工作:
下载mod_jk.so
打开链接找到合适的文件下载,下载后改名为mod_jk.so
修改Apache相关文件
1、将mod_jk.so上传至/modules目录下
2、在/apache/conf目录下新建文件mod_jk.conf
#Load mod_jk module
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"
#Send servlet for context /examples to worker named ajp13
JkMount /servlet/* ajp13
#Send all files under MyProject for to worker named ajp13
JKMount /MyProject ajp13
3、在/apache/conf目录下新建文件workers.properties
worker.list=ajp13
worker.ajp13.port=8009
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1
4、修改/conf/httpd.conf
Listen 80改为Listen 你的IP:80
ServerName localhost:80
最后一行添加 Include conf/mod_jk.conf
找到DocumentRoot,记住它的值,后面有用。我的是/www/apache/htdocs
5、添加<VirtualHost>节点
复制代码 代码如下:
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
ServerName
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /MyProject
ProxyPassReverse /MyProject
</VirtualHost>
复制代码 代码如下:
<?xml version='1.0' encoding='utf-8'?>
<Context displayName="Welcome to Tomcat" docBase="" path="" debug="0"></Context>
新闻热点
疑难解答