If you're load balancing with mod_jk, you can put a load balancer worker in your jk properties file, and then have requests forwarded to all the workers that are members of that load balancer. That's a great way to share the load.
But if you're running applications that rely on a series of linked pages (sessions) the you really don't want your client's requests to be forwarded at random - you want to pass them back to the same worker they were talking to last time. In real life, this is like saying that if you go into a shop, you can pay at any till, but if you make a series of telephone calls to sort out a complicated utility bill you really want to get through to the same clerk to serve you each time.
You can set up this "sent back to the same person" scenario if your application is written using Java's session classes; in the workers configuration file add a line to specify the domain for each host, and a line to set sticky sessions on in the balance worker:
In your Tomcat configuration file on EVERY server, set the jvmRoute of the engine to be the same as the domain name stated in the worker entry - for example:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="oak">
Remember that is you stop and start your various servers during testing, that will NOT have reset / cleared the cookies held at the browsers you are testing from and you may see some odd effects - what you are doing is like changing a program, but saving the variables. It's a good idea to stop everything, clear out all relevant cookies and caches, and restart as a final test before releasing the system to users.
If you are using mod_jk and have turned sticky sessions on, but your sessions are failing to stick, you have probably failed to set the domain, or you have failed to set the jvmRoute, or you are using a non-standard cookie name to implement the stickyness!
With Apache 2.2, mod_proxy_balancer
has replaced many uses of mod_jk
; similar setup principles apply - there are more mod_proxy resources here
We cover the connection of Apache httpd to Apache Tomcat on our public Deploying Apache httpd and Tomcat course
, and we also cover them as appropriate on private courses; the examples above come from this afternoon's examples on a private course.
- although the build documentation for mod_jk talks about Apache 1.3 and Apache 2.0, the (2.0) scheme works perfectly well for you to build for 2.2. However, once you have built a mod_jk library, that built file will ONLY work reliably with the version / subversion you built it for. It's no good getting someone else's 2.0.43 and expecting it to work on 2.0.44! (written 2009-02-12, updated 2009-02-13)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesA601 - Web Application Deployment - Apache httpd - an overview 
Apache httpd - a robust, open source web server - (2013-04-16) 
An FAQ on the Apache httpd and Apache Tomcat web servers, and on using them together - (2009-05-17) 
Why put Apache httpd in front of Apache Tomcat - (2009-03-12) 
Internal Dummy Connections on Apache httpd - (2009-03-02) 
Tuning httpd / the supermarket checkout comparison - (2009-02-26) 
Apache httpd and Apache Tomcat miscellany - (2009-01-30) 
Keeping on an even keel - (2008-11-21) 
Keep the client experience easy - single server contact point - (2008-03-27) 
Apache, Tomcat, Jakarta, httpd, web server - what are they? - (2007-07-13) 
The LAMP Cookbook - Linux, Apache, MySQL, PHP / Perl - (2006-11-13) 
Web Application Components - (2006-03-28) 
Why run two different web servers - (2006-01-25)
Some other Articles
Wiltshire Rail Service Updatehttpd, Tomcat and PHP course enhancementsError: Cant read xxxxx: no such variable (in Tcl Tk)The InvokerSticky Sessions with mod_jk (httpd to Tomcat)The Interview and The LiftJava Tag Libraries / how they work / Tomcat Deployment1234567890 ... coming up on Friday 13thThrough Snow and Flood to Linux and TomcatHuawei D100 Wireless Router - Mobile Internet