Apache Reverse proxy tomcat (mod_proxy mode)

Source: Internet
Author: User

Apache Reverse proxy tomcat (mod_proxy mode)

Environment uses two servers, Apache server IP is 192.168.8.18,tomcat server address is 192.168.8.16

Tomcat Build (192.168.8.16):


To install the JDK:

Download binary package on official website

# chmod +x jdk-6u45-linux-i586-rpm.bin# give Execute permissions #./jdk-6u45-linux-i586-rpm.bin# execution

Installed by default in the/usr/java directory

# vim/etc/profile.d/java.sh Export java_home=/usr/java/jdk1.6.0_45# Declaration environment variable Export path= $PATH: Append PATH variable $JAVA _home/bin# # java-version# Test Success or not


To install Tomcat:

# wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-7/v7.0.82/bin/apache-tomcat-7.0.82.tar.gz# Tar XF APACHE-TOMCAT-7.0.82.TAR.GZ # cp apache-tomcat-7.0.82/usr/local/-rf# cd/usr/local/# LN-SV apache-tomcat-7.0.82 Tomcat # Vim/etc/profile.d/tomcat.shexport Catalina_home=/usr/local/tomcatexport path= $PATH: $CATALINA _home/bin# vim/etc/ rc.d/rc.local/usr/local/tomcat/bin/catalina.sh start# Boot #/usr/local/tomcat/bin/catalina.sh start# start Tomcat Service

Open the http://192.168.8.16:8080/test page is normal

Apache Build (192.168.8.18):


Preparatory work:

# tar XF apr-1.6.3.tar.gz # tar XF apr-util-1.5.1.tar.gz# tar xf httpd-2.4.29.tar.gz#./configure--prefix=/usr/local/apr# make# make install# cd apr-util-1.5.1#./configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr# make# do in stall# yum-y Install Pcre-devel


Apache Installation:

To use Mod_proxy to connect to a Tomcat instance, Apache has already loaded mod_proxy, Mod_proxy_http, MOD_PROXY_AJP, and Proxy_balancer_ Module (used when implementing the Tomcat cluster)

#./configure--prefix=/usr/local/apache--sysconfdir=/etc/httpd--enable-so--enable-rewirte--enable-ssl-- enable-cgi--enable-cgid--enable-modules=most--enable-mods-shared=most--enable-mpms-shared=all--with-mpm=event- -WITH-APR=/USR/LOCAL/APR--with-apr-util=/usr/local/apr-util--enable-proxy--enable-proxy-http--ENABLE-PROXY-AJP --enable-proxy-balancer# make# make install# vim/etc/rc.d/rc.local#/usr/local/apache/bin/apachectl start# vim/etc/ profile.d/apache.sh export path= $PATH:/usr/local/apache/bin

Configure Apache to connect to Tomcat via the Mod_proxy module:

# Vim Httpd.conf

#DocumentRoot "/usr/local/apache/htdocs"# comment out, open the virtual host

include/etc/httpd/extra/httpd-proxy.conf# Add one line at a time point to stand-alone configuration file

# vim/etc/httpd/extra/httpd-proxy.conf# Edit configuration file, add the following content

<virtualhost *:8080>

Proxyvia OFF

Proxyrequests OFF

proxypass/http://192.168.8.16:8080/

proxypassreverse/http://192.168.8.16:8080/

<proxy *>

Require all granted

</Proxy>

<location/>

Require all granted

</Location>

</VirtualHost>

Description of the above Apache directive:


Proxypreservehost {on| OFF}: If this feature is enabled, the agent sends the host: line from the user request message to the backend server instead of using the server address specified by Proxypass. If you want to support virtual hosts in a reverse proxy, you need to turn this on, or you won't have to turn on this feature.


Proxyvia {on| Off| full| Block}: Used to control whether the HTTP header uses via:, which is primarily used to control the flow of proxy requests in the multilevel proxy. The default is off, which means that the feature is not enabled; On indicates that each request and response message is added via:;full indicates that each via: Row adds the current Apache server version number information, and block means that the Via: in each proxy request message will be removed.


proxyrequests {on| OFF}: Whether to turn on the functionality of Apache forward proxy; When enabled, the Mod_proxy_http module must be enabled in order to proxy the HTTP protocol. Also, if you set proxypass for Apache, you must set proxyrequests to OFF.


Proxypass [path]!| URL [key=value key=value ...] : Associates a backend server URL with a virtual path to the current server as the path to provide the service, path is a virtual path on the current server, and the URL is a URL path on the back-end server. You must set the value of proxyrequests to OFF when you use this directive. It is important to note that if path ends with "/", the corresponding URL must also end with "/" and vice versa.

In addition, the Mod_proxy module is httpd

# Apachectl Start

Access to the http://192.168.8.18:8080/test whether the agent 192.168.8.16:8080


Apache Reverse proxy tomcat (mod_proxy mode)

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.