Jsp和PHP共用80端口整合Apache和Tomcat(访问时无需加端口号)
程序员文章站
2023-11-29 21:17:16
目的: 整合apache和tomcat,使得java工程和php工程都能共用80端口,访问网站时,无需在地址栏中加端口号。 环境说明: linux centos 32位 a...
目的:
整合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工程了,但是请注意,最后的"/"不能少!
如果想要用户无需添加“/”,请看“”
----------------------------------------------------------------------------------------------
上一篇: 深度解析搜索引擎蜘蛛工作的原理