Tomcat is a combination with Apache to implement anti-proxy (based on module Mod_jk,mod_proxy)

Source: Internet
Author: User

Apache Server: 192.168.1.155

Yum-y Install httpd

[Email protected] conf]# httpd-v

Server version:apache/2.2.15 (Unix)

Server Built:may 11 2016 19:28:33

Based on the MOD_JK module:

wget http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.41-src.tar.gz

Tar XF tomcat-connectors-1.2.41-src.tar.gz

CD tomcat-connectors-1.2.41-src/native

./configure--with-apxs=/usr/sbin/apxs

Make && make install

See if mod_jk.so already exists

Ls-l/etc/httpd/modules/mod_jk.so

[Email protected] conf]# ls-l/etc/httpd/modules/mod_jk.so

-rwxr-xr-x. 1 root root 1215731 May 05:35/etc/httpd/modules/mod_jk.so

Configuring the MOD_JK Module

cd/etc/httpd/conf.d/

Vim mod_jk.conf

[email protected] conf.d]# cat mod_jk.conf

LoadModule Jk_module modules/mod_jk.so

Jkworkersfile/etc/httpd/conf.d/workers.properties

JklogfileLogs/mod_jk.log

JkloglevelDebug

Jkmount/* TOMCAT1

Jkmount /STATUS/STAT1

[email protected] conf.d]# cat workers.properties

Worker.list=tomcat1,stat1

worker.tomcat1.port=8009

worker.tomcat1.host=192.168.1.155

Worker.tomcat1.type=ajp13

Worker.tomcat1.lbfactor=1

Worker.stat1.type = Status

Check the syntax, OK.

Service httpd Start


Install Tomcat

Installing JDK7

Curl-lo-h "Cookie:oraclelicense=accept-securebackup-cookie" \

"HTTP://DOWNLOAD.ORACLE.COM/OTN-PUB/JAVA/JDK/7U75-B13/JDK-7U75-LINUX-X64.RPM"-K


RPM-IVH jdk-7u75-linux-x64.rpm

vim/etc/profile.d/java.sh

Export java_home=/usr/java/jdk1.7.0_75

Export path= $JAVA _home/bin: $PATH

. /etc/profile.d/java.sh


Installing Tomcat

wget http://ftp.riken.jp/net/apache/tomcat/tomcat-7/v7.0.70/bin/apache-tomcat-7.0.70.tar.gz

Tar zxvf apache-tomcat-7.0.59.tar.gz

MV APACHE-TOMCAT-7.0.70/USR/LOCAL/TOMCAT7

vim/etc/profile.d/tomcat.sh

Export CATALINA_HOME=/USR/LOCAL/TOMCAT7

Export path= $CATALINA _home/bin: $PATH

. /etc/profile.d/tomcat.sh

Useradd-m-D/USR/TOMCAT7 TOMCAT7

Chown-r TOMCAT7. /usr/local/tomcat7/*


Given Tomcat provides script:

Script:

[email protected] ~]# cat tomcat7.sh

#!/bin/bash

Tomcat_home= "/USR/LOCAL/TOMCAT7"

Tomcat_user= "TOMCAT7"

Lockfile= "/VAR/LOCK/SUBSYS/TOMCAT7"

. /etc/init.d/functions


Start () {

su-$tomcat _user-c $tomcat _home/bin/startup.sh

[$?-eq 0] && {

Action "Starting Tomcat"/bin/true

Touch $LOCKFILE

}

}


Stop () {

$tomcat _home/bin/shutdown.sh

[$?-eq 0] && {

Action "Stopping Tomcat"/bin/true

Rm-f $LOCKFILE

}

}


Case "$" in

Start

Start

;;

Stop

Stop

;;

Restart

Stop

Start

;;

*)

echo "Usage: $ {Start|stop|restart}"

Exit 1

;;

Esac

Replace the Tomcat original browser page

Cd/usr/local/tomcat7/webapps/root

MV Index.jsp Index.jsp.bak

Vim index.jsp

<%@ page language= "java"%>

<%@ page import= "java.util.*"%>

<title>jsp Test page</title>

<body>

<%

Out.println ("Hello world!");

%>

</body>

Browser access: http://192.168.1.155:8080, appears as follows

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/84/4F/wKioL1eMhwORCUZNAAA4X5JuC8M579.jpg "title=" 1.jpg " alt= "Wkiol1emhworcuznaaa4x5juc8m579.jpg"/>

Combined with Apache and Tomcat, the MOD_JK module has just been configured with information

Service httpd Restart

Browser access: http://192.168.1.155 appears as follows

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/84/4F/wKiom1eMh2mjOQqjAAA1pZsASuw114.jpg "title=" 2.jpg " alt= "Wkiom1emh2mjoqqjaaa1pzsasuw114.jpg"/>

Then the Apache-based reverse proxy succeeds (based on the MOD_JK module)


Based on the Mod_proxy module (removing just two profiles from Mod_jk.conf.bak, etc.)

[email protected] conf.d]# cat mod_proxy.conf

Proxyvia OFF

Proxyrequests OFF

proxypass/ajp://192.168.1.155:8009/

proxypassreverse/ajp://192.168.1.155:8009/

<proxy *> (since the httpd version is 2.2, the 2.4 version has changed here)

Order Allow,deny

Allow from all

</Proxy>

<location/>

Order Allow,deny

Allow from all

</Location>

Configuration based on the apache2.4 version:

Proxyvia OFF

Proxyrequests OFF

proxypass/ajp://192.168.1.155:8009/

#ProxyPass/my-webapp Http://www.magedu.com:8080/my-webapp: Access to Tomcat is not the default directory but/my-webapp the following

proxypassreverse/ajp://192.168.1.155:8009/

<location/>

Require all granted

</Location>

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M01/84/4F/wKioL1eMjaiiL9lsAAAzTpSKZa4066.jpg "title=" 3.jpg " alt= "Wkiol1emjaiil9lsaaaztpskza4066.jpg"/>

So the reverse generation based on the Mod_proxy module was also successful.


Studied the apache2.4 version of the MOD_JK module, but has been an error, there is time to re-operate again

Tomcat is a combination with Apache to implement anti-proxy (based on module Mod_jk,mod_proxy)

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.