訪問Tomcat時無需加端口號

整合Apache和Tomcat,使得Java工程和PHP工程都能共用80端口,訪問網站時,無需在地址欄中加端口號,具體實現以下,感興趣的朋友能夠參考下哈web

目的:apache

整合Apache和Tomcat,使得Java工程和PHP工程都能共用80端口,訪問網站時,無需在地址欄中加端口號。tomcat

環境說明:app

Linux CentOS 32位webapp

Apache 2.2.2jsp

Tomcat 7.0.37網站

準備工做:spa

下載mod_jk.sodebug

http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/orm

打開連接找到合適的文件下載,下載後更名爲mod_jk.so

修改Apache相關文件

一、將mod_jk.so上傳至/modules目錄下

二、在/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

三、在/apache/conf目錄下新建文件workers.properties

worker.list=ajp13

worker.ajp13.port=8009

worker.ajp13.host=localhost

worker.ajp13.type=ajp13

worker.ajp13.lbfactor=1

四、修改/conf/httpd.conf

Listen 80改成Listen 你的IP:80

ServerName localhost:80

最後一行添加 Include conf/mod_jk.conf

找到DocumentRoot,記住它的值,後面有用。個人是/www/apache/htdocs

五、添加<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相關文件

一、在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>

二、修改/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">

相關文章
相關標籤/搜索