This post was last edited by rootsecurity at, January 28 ,.
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: <Proxy balancer: // localCluster>
BalancerMember ajp: // localhost: 8009
</Proxy>
RewriteEngine On
ProxyPreserveHost On
RewriteRule ^/$ balancer: // localCluster/[P, L, NC]
RewriteRule ^/(. *) $ balancer: // localCluster/$1 [P, L, NC]
Author rootsecurity