Objective:
Combining Apache and Tomcat enables both Java Engineering and PHP engineering to share 80 ports, and when you visit a Web site, you don't need to add a port number to the address bar.
Environment Description:
Linux CentOS 32-bit
Apache 2.2.2
Tomcat 7.0.37
preparatory work:
Download mod_jk.so
http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/
Open the link to find the appropriate file download, after downloading renamed to Mod_jk.so
modify Apache related files
1, upload the mod_jk.so to the/modules directory
2. Create a new file in the/apache/conf directory 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. Create a new file in the/apache/conf directory workers.properties
Worker.list=ajp13
worker.ajp13.port=8009
Worker.ajp13.host=localhost
Worker.ajp13.type=ajp13
Worker.ajp13.lbfactor=1
4. Modify/conf/httpd.conf
Listen 80 instead Listen your ip:80.
ServerName localhost:80
Last line add Include conf/mod_jk.conf
Find DocumentRoot and remember its value, which is useful later. Mine is/www/apache/htdocs.
5, add <VirtualHost> node
Copy Code code as follows:
<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>
"Note:" The name of the Scarlet Letter must be identical, that is, it must match the project name under Tomcat
Modify Tomcat related files
1. Add Root.xml under Tomcat
My directory is like this:/opt/tomcat/conf/catalina/localhost
New Root.xml
Copy Code code as follows:
<?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<context displayname= "Welcome to Tomcat" docbase= "path=" "debug=" 0 "></Context>
2. Modify/conf/server.xml
I. Modify the default port number (or do not change, the default is generally 8080)
<connector port= "9090" protocol= "http/1.1" connectiontimeout= "20000" redirectport= "8443"/>
II. Check the AJP port number (8009 is not modifiable, if the sentence is commented out, uncomment)
<connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/>
Iii. Inspection <HOST> Node
-----------------------Friendly Tips-------------------------------------------------------------
At this point, you can access the Java project through domain name/project name/, but please note that the final "/" Can not be less!
If you want users to add "/", see "Add a backslash after the site directory"
----------------------------------------------------------------------------------------------