TOMCAT: Configuring reverse proxy, load balancing with Apache

Source: Internet
Author: User

Apache reverse proxy, load balancer

Preparatory work

1, 2 Tomcat instances

2. Installing Apache server2.2

Configure reverse proxy based on Apache server

In this configuration, only Apache server is used and no tomcat is used.

1) ${apacheserver}/conf/extra/httpd-vhosts.conf in configuring a virtual host that uses a reverse proxy

<virtualhost *:80>

ServerAdmin [email protected]

ServerName www.test.com

Proxyrequests OFF

<proxy *>

Order Deny,allow

Allow from all

</Proxy>

Proxypass/test Http://192.168.1.250:8080/test

Proxypassreverse/test Http://192.168.1.250:8080/test

</VirtualHost>

Here is a virtual host configured in Apache.

Port is 80

ServerAdmin: is the email address

ServerName: Is the domain name configured in the Hosts file

Proxypass/test Http://192.168.1.250:8080/test is a configuration that uses this Prxoy when it represents access to resources under Http://www.test.com/test.

2) in the ${apacheserver}/conf/httpd.conf file, do the following configuration

LoadModule Proxy_module modules/mod_proxy.so and

LoadModule Proxy_http_module modules/mod_proxy_http.so Before the comment is removed

To allow Apache to load the proxy module when it starts

Remove the comments from the previous page of the include conf/extra/httpd-vhosts.conf

The goal is to have Apache load the virtual host configuration when it starts

Configure reverse proxy and load balancing based on Apache server + tomcat

1. Configuration of 2 Tomcat instances

1) adjust their ports (shutdown,http or AJP)

2) Specify route

<engine name= "Catalina" defaulthost= "localhost" jvmroute= "worker1" >

Two Tomcat instances, one is worker1 and the other is worker2. Use it later when you configure Apache.

2. Configure Proxy on Apache

1) loading related agent modules

Now that you want to use proxy access, you must have an agent module.

Make the following configuration in ${apacheserver}/config/http.conf:

The command to enable Proxy is:

LoadModule Proxy_module modules/mod_proxy.so

LoadModule Proxy_balancer_module modules/mod_proxy_balancer.so

LoadModule Proxy_http_module modules/mod_proxy_http.so

If you want to configure the AJP protocol, you also need to mod_proxy_ajp.so the previous #.

2 ) define reverse proxies and load balancing

The configured source code is:

<ifmodule proxy_balancer_module>

# define a Load Balance Proxy based HTTP protocol

<ifmodule proxy_http_module>

<proxy balancer://myhttplb>

Balancermember http://localhost:18080/examples loadfactor=80 Route=worker1

Balancermember http://localhost:28080/examples loadfactor=20 Route=worker2

</Proxy>

Proxyrequests off

Proxypass/examples Balancer://myhttplb/stickysession=jsessionid Nofailover=off

Proxypassreverse/examples balancer://myhttplb/

</IfModule>

# define a Load Balance Proxy based AJP protocol

<ifmodule proxy_ajp_module>

<proxy balancer://myajplb>

Balancermember ajp://localhost:18080/examples loadfactor=80 Route=worker1

Balancermember ajp://localhost:28080/examples loadfactor=20 Route=worker2

</Proxy>

Proxyrequests off

Proxypass/examples Balancer://myajplb/stickysession=jsessionid Nofailover=off

Proxypassreverse/examples balancer://myajplb/

</IfModule>

</IfModule>

In the above configuration, two reverse proxies with load balancing function are launched according to the loaded module, one based on the HTTP protocol and one based on the AJP protocol. Here is a description of the HTTP protocol:

<proxy balancer://myhttplb>

Balancermember http://localhost:18080/examples loadfactor=80 Route=worker1

Balancermember http://localhost:28080/examples loadfactor=20 Route=worker2

</Proxy>

Define a proxy that has load balancing enabled and the name is BALANCER://MYHTTPLB

There are two members: Worker1 and Worker2. The weights are 80, 20, respectively.

Proxypass/examples Balancer://myhttplb/stickysession=jsessionid Nofailover=off

This configuration indicates:

When accessing resources under Http://apacheServerIp:port/examples, it is handled by the load Balancer balancer://myhttplb/.

Stickysession indicates that sticky sessions are enabled.

The nofailover is used to configure failover.

Proxypassreverse/examples balancer://myajplb/

Used to adjust the URL in the HTTP response header sent by the reverse proxy server

If you do not understand the Proxypass configuration, you can refer to the

Http://blog.chinaunix.net/uid-13328647-id-2902236.html

Test

Access Http://localhost/examples.

Examples is an application under Tomcat/webapps, so it must be accessible.

TOMCAT: Configuring reverse proxy, load balancing with Apache

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.