Complete Apache 2.2-AJP Load Balance via mod_proxy
Complete guide for apache-http server load balancing via mod_proxy and some performance enhancements
required modules:
proxy_module
proxy_ajp_module
proxy_balancer_module
![]()
1. open your java application AJP connector
for tomcat un comment AJP connector as below
<Connector port=”8009” protocol=”AJP/1.3″ redirectPort=”8443″ />
2. Load Apache modules
include or uncomment those lines at httpd.conf
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
3. write new httpd-conf as httpd-ajp.conf
<Location /balancer-manager>
SetHandler balancer-manager
</Location><Proxy balancer://ajpCluster>
BalancerMember ajp://localhost:8009 route=s1
BalancerMember ajp://localhost:9009 route=s2
BalancerMember ajp://localhost:7009 route=s3
</Proxy>
<Location /jspapp1>
ProxyPass balancer://ajpCluster/jspapp1 stickysession=JSESSIONID
</Location>
<Location /jspapp2>
ProxyPass balancer://ajpCluster/jspapp2 stickysession=JSESSIONID
</Location>
/balancer-manager is to monitor your load balance cluster nodes
you can see fails and last status for java ajp connectors/Servers
http://yourapachehost/balancer-manager
Proxy balancer://ajpCluster
is your load balance /cluster definition for your apache server
in example is assuming 3 java application server with ajp connectors at 7009,8009,9009 working at at localhost
/jspapp1 and /jspapp2 is your jsp/java applications rename it with your application context name
4. Extras (GZip)
define mod_deflate in httpd.conf
LoadModule deflate_module modules/mod_deflate.so
add gzip compression for jspapp s
<Location /jspapp2>
ProxyPass balancer://ajpCluster/jspapp2 stickysession=JSESSIONID
AddOutputFilterByType DEFLATE text/html text/plain text/xml
</Location>
see:
multiple tomcat instance – single setup
![Reblog this post [with Zemanta]](http://img.zemanta.com/reblog_e.png?x-id=fd79928f-4f2c-46ed-8f18-92cea713a352)



참고
great tips. thank you!
Great post, this got me proxying requests via ajp_proxy from Apache to multiple virtual Xen instances running tomcat6 on the back end. Very cool, appreciate the effort.
Hi Dear,
I have configured the same but whenever my one instances goes down applications is not switching on another…..can u guid me ..
Thanks
hi lovelesh,
I am not sure but it was working,
you can check, /balancer-manager if all your applications are running or not ?
but there can be one problem i guess, your java server may be not dead (its ajp port is still open) but crashed by out-of-memory errors ? and not responding properly !
oh cool, this information is really useful and definately is comment worthy! hehe. I’ll see if I can try to use some of this information for my own blog. Thanks!
hi,
this is really a vague inforation. can you please provide some clear step by step , how do we setup the mod_proxy.
i have difficulty in understanding the Step 3. Is that to change the existing httpd.conf to http-ajp.conf?
-Raghu boyalakuntla
Cool man grt article
Nice. Worked for me, Thanks
Hi guys, Thanks for the wonderful post here.
I have a problem to load mod_deflate .so. I get following error
httpd: Syntax error on line 61 of /app3/apache2/conf/httpd.conf: Cannot load /app3/apache2/modules/mod_deflate.so into server: /app3/apache2/modules/mod_deflate.so: undefined symbol: inflateEnd
Please help me on this.
Thanks in advance.
hi Joel,
it seems you have incompatible so module with your server library, be sure you get the same ‘so’ library version/build number with your apache version.
in most cases you need to build them all locally or get the whole distribution from one place.
Cheers