Jsp and PHP share port 80 to integrate Apache and Tomcat (no port number is required during access)

Source: Internet
Author: User

Purpose:
The integration of Apache and Tomcat allows both Java and PHP projects to share port 80. when accessing a website, you do not need to add a port number in the address bar.

Environment Description:
Linux CentOS 32-bit
Apache 2.2.2
Tomcat 7.0.37

Preparations:
Download mod_jk.so
Http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/
Open the link and find the appropriate file to download. After the download, rename it mod_jk.so.

Modify Apache files
1. Upload mod_jk.so to the/modules directory.
2. Create the file mod_jk.conf in the/apache/conf directory.
# 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 the workers. properties file in the/apache/conf directory.
Worker. list = ajp13
Worker. ajp13.port = 8009
Worker. ajp13.host = localhost
Worker. ajp13.type = ajp13
Worker. ajp13.lbfactor = 1

4. Modify/conf/httpd. conf
Change Listen 80 to Listen your IP address: 80
ServerName localhost: 80

Add Include conf/mod_jk.conf in the last line.
Find DocumentRoot and remember its value, which will be useful later. My website is/www/apache/htdocs.

5. Add a <VirtualHost> nodeCopy codeThe Code is 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 Red part must be the same, that is, it must be the same as the project name under tomcat.
Modify Tomcat files
1. Add ROOT. xml under tomcat
My directory is like this:/opt/tomcat/conf/Catalina/localhost
Create ROOT. xmlCopy codeThe Code is 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 it. The default value is generally 8080)
<Connector port = "9090" protocol = "HTTP/1.1" connectionTimeout = "20000" redirectPort = "8443"/>
II. Check the AJP port number (8009 cannot be modified. If this sentence is commented out, uncomment it)

<Connector port = "8009" protocol = "AJP/1.3" redirectPort = "8443"/>
III. Check the <HOST> node
<Host name = "localhost" appBase = "webapps" unpackWARs = "true" autoDeploy = "true">

----------------------- Friendly reminder -------------------------------------------------------------
Now, you can access the java project through "Domain Name/project name/", but please note that the last "/" cannot be less!
If you do not need to add "/", see "add a backslash after the website directory"
Bytes ----------------------------------------------------------------------------------------------

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.