Configuring Tomcat Load Balancer with Apache web server using Mod Proxy is quite easy. It’s easy when you follow the sequence, and all goes well. I have listed following step-by-step on how to configure Apache with Tomcat to configure Load Balancer using Mod Proxy. Having load-balanced is always recommended in a production environment for better availability.

Apache Web Server Configuration

Enable proxy_module, proxy_balancer_module and proxy_http_module in httpd.conf of Apache web server

Add proxy pass along with balancer name for application context root. In this example, I have a proxy path as examples and balancer name as mycluster. Very important to include stickysession as not having this option will distribute the same request to multiple Tomcat server, and you will have session expiry issues in an application. As you can see in above configuration, I have added a route in BalancerMember so route value can be appended to session ID. Now, let’s configure Apache to print JSESSIONID in access logs.

Add following in LogFormat directive

Ex:

Restart Apache Web Server

Tomcat Configuration

You must configure tomcat instances with same route id as you did in BalancerMember above.

Add jvmRoute parameter in server.xml of Tomcat. This must be added in Engine name tag.

Tomcat instance configured with 8080 port Tomcat instance configured with 8090 port

Restart Tomcat server

Verification

Generate some load on application and check access log of apache server to ensure your request is getting routed to only one tomcat instance. You will also notice your session ID is appended to the route as shown in below example. Ex: I hope this helps you in configuring Tomcat Load Balancer with Apache Mod Proxy and Session Sticky. If interested to learn about Tomcat administration then check this online course.

Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 93Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 92Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 1Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 3Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 98Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 22Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 42Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 26Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 78Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 36Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 68Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 82Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 78Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 37Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 47Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 64Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 68Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 94Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 21Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 98Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 24Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 73Tomcat Load Balancer with Apache using Mod Proxy and Session Sticky - 28