An Apache + Tomcat integration document

Source: Internet
Author: User
At the end of this post, the background is edited by rootsecurity from 2012-2-2814: 12. as the JSP environment is required, I will write an article on Apache + Tomcat integration. Required software: 1、httpd-2.2.22.tar.gz2、tomcat-7.0.23.tar.gz 3, tomcat-connectors-1.2.30.t... This post was last edited by rootsecurity at PM
 
 
Background: As the JSP environment is required, I will write an article on Apache + Tomcat integration.
 
Required software:
1、httpd-2.2.22.tar.gz
2、tomcat-7.0.23.tar.gz
3、tomcat-connectors-1.2.30.tar.gz
4. jdk-6U21-i586.bin
 
Installation steps:
1. first install Apache [root @ localhost ~] # Tar zxvf httpd-2.2.22.tar.gz
 
[Root @ localhost ~] # Cd httpd-2.2.22
 
[Root @ localhost httpd-2.2.22] #./configure -- prefix =/usr/local/apache-2.2.22 \
 
-- Enable-headers \
 
-- Enable-mime-magic \
 
-- Enable-proxy \
 
-- Enable-so \
 
-- Enable-rewrite \
 
-- Enable-ssl \
 
-- Enable-suexec \
 
-- With-defined Ded-apr \
 
-- With-mpm = prefork \
 
-- With-ssl =/usr \
 
-- Disable-userdir \
 
-- Disable-cgid \
 
-- Disable-cgi
 
[Root @ localhost httpd-2.2.22] # make & make install
 
[Root @ localhost httpd-2.2.22] # cd ../
 
[Root @ localhost ~] #
2. install apache-tomcat [root @ localhost ~] # Tar zxvf apache-tomcat-7.0.23.tar.gz
 
[Root @ localhost ~] # Mv apache-7.0.23/usr/local
 
[Root @ localhost ~] # Ln-s/usr/local/tomcat-7.0.23/usr/local/tomcat
3. install JDK [root @ localhost ~] # Chmod + x./jdk-6U21-i586.bin
 
[Root @ localhost ~] #./Jdk-6U21-i586.bin
 
Uppacking ....
 
....
 
...
 
[Root @ localhost ~] # Mv jdk1.6.0 _ 21/usr/local/
 
[Root @ localhost ~] # Ln-s/usr/local/jdk1.6.0 _ 21/usr/local/jdk
4. modify the environment variable (/etc/profile) TOMCAT_HOME =/usr/local/tomcat
 
JAVA_HOME =/usr/local/jdk
 
JRE_HOME = $ JAVA_HOME/jre
 
CLASSPATH =.: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jar
 
PATH = $ JAVA_HOME/bin: $ JAVA_HOME/jre/bin: $ PATH
 
Export TOMCAT_HOME JAVA_HOME JRE_HOME CLASSPATH PATH
Make environment variables take effect immediately [root @ localhost ~] # Source/etc/profile
5. install tomcat-connector [root @ localhost ~] # Tar zxvf tomcat-connector-1.2.30.tar.gz
 
[Root @ localhost ~] # Cd tomcat-connector-1.2.30/
 
[Root @ localhost tomcat-connector-1.2.30] # cd native
 
[Root @ localhost native] #./buildconf. sh
 
[Root @ localhost native] #./configure -- with-apxs =/usr/local/apache-2.2.22/bin/apxs
 
[Root @ localhost native] # make & make install
 
[Root @ localhost native] # cd ../
 
[Root @ localhost ~] #
6. check whether the modules directory under the apache installation directory contains mod_jk.so.
7. integrate Apache + Tomcat
There are two methods for integration: Reverse proxy and mod_jk. Since mod_jk is installed here, I will not talk about reverse proxy. at the end of the article, I will mention the reverse proxy method. Mod_jk is used for apache + tomcat integration.
Find the conf/extra directory under the apache installation directory (for convenience, put the configuration file in this directory)
Create a configuration file named mod_jk.conf and enter the following content. JkWorkersFile conf/extra/workers. properties
 
JkLogFile logs/mod_jk.log
 
JkShmFile logs/jk-runtime-status
 
JkLogLevel info
 
JkLogStampFormat "[% a % B % d % H: % M: % S % Y]"
 
JkOptions + ForwardKeySize + ForwardURICompat-ForwardDirectories
 
JkRequestLogFormat "% w % V % T"
 
 
 
# Sample JkMounts. Replace these with the paths you wowould
 
# Like to mount from your JSP server.
 
# Syntax: JkMount $ {URL_DIR}/*. jsp worker_name
 
 
 
JkMount/images/avatar/* worker1
 
JkMount/*. jsp worker1
 
JkMount/*. page worker1
 
JkMount/*. cic worker1
 
JkMount/*. do worker1
 
JkMount/*. action worker1
Save and create a new workers. properties File. enter the following content: worker. list = worker1
 
Worker. worker1.port = 8009
 
Worker. worker1.host = localhost
 
Worker. worker1.type = ajp13
 
Worker. woker1.lbfactor = 1
Finally, modify the DocumentRoot file of apache httpd. conf to be consistent with tomcat. Add index. jsp, index. do index. action to the DirectoryIndex option and restart apache.
Write a test page for index. jsp: <%
 
Out. println ("hello java ");
 
%>
Access verification successful


Here we will talk about the integration of reverse proxy for apache + tomcat. since it is a reverse proxy, tomcat-connectors does not need to be installed and the configuration file does not need to be changed, you only need to install apache, tomcat, and jdk. after you enable the respective services, modify httpd. conf. add the following statement at the end of the file:
 
BalancerMember ajp: // localhost: 8009
 

 
RewriteEngine On
 
ProxyPreserveHost On
 
RewriteRule ^/$ balancer: // localCluster/[P, L, NC]
 
RewriteRule ^/(. *) $ balancer: // localCluster/$1 [P, L, NC]


Author rootsecurity
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.