相思资源网 Design By www.200059.com
目的:
整合Apache和Tomcat,使得Java工程和PHP工程都能共用80端口,访问网站时,无需在地址栏中加端口号。
环境说明:
Linux CentOS 32位
Apache 2.2.2
Tomcat 7.0.37
准备工作:
下载mod_jk.so
http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/
打开链接找到合适的文件下载,下载后改名为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 www.sample.cn/m
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /MyProject http://www.sample.cn/MyProject/pages/login.jsp
ProxyPassReverse /MyProject http://www.sample.cn/MyProject/pages/login.jsp
</VirtualHost>
【注意:】红字部分的名称必须一致,也就是说必须和tomcat下的工程名一致
修改Tomcat相关文件
1、在tomcat下添加ROOT.xml
我的目录是这样的:/opt/tomcat/conf/Catalina/localhost
新建ROOT.xml
复制代码 代码如下:
<?xml version='1.0' encoding='utf-8'?>
<Context displayName="Welcome to Tomcat" docBase="" path="" debug="0"></Context>
2、修改/conf/server.xml
I.修改默认端口号(也可以不改,默认一般为8080)
<Connector port="9090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
II.检查AJP端口号(8009不可修改,若这一句被注释掉了,取消注释)
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
III.检查<HOST>节点
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
-----------------------友情提示-------------------------------------------------------------
至此,就可以通过“域名/工程名/”访问java工程了,但是请注意,最后的"/"不能少!
如果想要用户无需添加“/”,请看“在网站目录后添加反斜杠”
----------------------------------------------------------------------------------------------
整合Apache和Tomcat,使得Java工程和PHP工程都能共用80端口,访问网站时,无需在地址栏中加端口号。
环境说明:
Linux CentOS 32位
Apache 2.2.2
Tomcat 7.0.37
准备工作:
下载mod_jk.so
http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/
打开链接找到合适的文件下载,下载后改名为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 www.sample.cn/m
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /MyProject http://www.sample.cn/MyProject/pages/login.jsp
ProxyPassReverse /MyProject http://www.sample.cn/MyProject/pages/login.jsp
</VirtualHost>
【注意:】红字部分的名称必须一致,也就是说必须和tomcat下的工程名一致
修改Tomcat相关文件
1、在tomcat下添加ROOT.xml
我的目录是这样的:/opt/tomcat/conf/Catalina/localhost
新建ROOT.xml
复制代码 代码如下:
<?xml version='1.0' encoding='utf-8'?>
<Context displayName="Welcome to Tomcat" docBase="" path="" debug="0"></Context>
2、修改/conf/server.xml
I.修改默认端口号(也可以不改,默认一般为8080)
<Connector port="9090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
II.检查AJP端口号(8009不可修改,若这一句被注释掉了,取消注释)
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
III.检查<HOST>节点
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
-----------------------友情提示-------------------------------------------------------------
至此,就可以通过“域名/工程名/”访问java工程了,但是请注意,最后的"/"不能少!
如果想要用户无需添加“/”,请看“在网站目录后添加反斜杠”
----------------------------------------------------------------------------------------------
标签:
Apache,Tomcat
相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com
暂无Jsp和PHP共用80端口整合Apache和Tomcat(访问时无需加端口号)的评论...