Apache & MOD_JK Connector Set Up

Khemnath chauhan
3 min readOct 29, 2022

--

As mentioned in my other article about apache, it’s mostly used as load balancer.

Here, we will be configuring a load balancer in front of Tomcat Server using the Apache HTTP Web Server and the mod_jk connector.

The Apache Tomcat Connectors project is part of the Tomcat project and provides web server plugins to connect web servers with Tomcat and other backends.

The supported web servers are:

  • the Apache HTTP Server with a plugin (module) named mod_jk.
  • Microsoft IIS with a plugin (extension) named ISAPI redirector (or simply redirector).
  • the iPlanet Web Server with a plugin named NSAPI redirector. The iPlanet Web Server was previously known under various names, including Netscape Enterprise Server, SunOne Web Server and Sun Enterprise System web server.

The mod_jk module uses the AJP (Apache JServ Protocol) protocol to send requests to the Tomcat containers. The AJP version typically used is ajp13.

Request-Flow Diagram

Who supports AJP protocols?

Tomcat supports ajp13 since Tomcat 3.2. Others servlet engines such as Jetty or JBoss also support the ajp13 protocol

The ajp12 protocol has been deprecated and you should no longer use it. The ajp14 protocol is considered experimental.

How does it work ?

In a nutshell a web server is waiting for client HTTP requests. When these requests arrive the server does whatever is needed to serve the requests by providing the necessary content.

Adding a servlet container may somewhat change this behavior. Now the web server needs also to perform the following:

  • Load the servlet container adaptor library and initialise it (prior to serving requests).
  • When a request arrives, it needs to check and see if a certain request belongs to a servlet, if so it needs to let the adaptor take the request and handle it.

The adaptor on the other hand needs to know what requests it is going to serve, usually based on some pattern in the request URL, and to where to direct these requests.

MOD_JK DOWNLOAD & SETUP:

Download site: https://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.31/x86_64/

Apache Tomcat Connectors (mod_jk) 1.2.31 for Linux x86_64Here you’ll find the module binaries for Apache HTTPD.All Modules have been build on RHEL-5 x86_64 and should work under any sufficiently recent Linux for x86_64. All binaries are 64Bit.The compiler used was gcc 4.1.2. The library libgcc has been linked in statically. Additional compilation flags were “-O2 -g -Wall -fno-strict-aliasing”To ensure compatibility with a wide variety of web server minor versions, all builds have been done using the configure flag — enable-api-compatibility.
  • mod_jk-1.2.31-httpd-2.2.x.so is for Apache 2.2.x. It has been build against version 2.2.3, but should work with Apache 2.2.0 and later. Rename to mod_jk.so before putting it in your modules directory or adjust your LoadModule statement.
  • mod_jk-1.2.31-httpd-2.0.x.so is for Apache 2.0.x. It has been build against version 2.0.52. Rename to mod_jk.so before putting it in your modules directory or adjust your LoadModule statement.

Copy the mod_jk module (.so) file to apache module folder:

  • Put mod_jk.so under /etc/httpd/modules

Update the apache httpd.conf to include below properties.

LoadModule jk_module "modules/mod_jk.so" 
JkWorkersFile "conf/worker.properties"
JkLogFile "logs/httpd/mod_jk.log"
JkLogLevel info

Add the VirtualHost and JkMount.

Use mod_jk’s JkMount directive to assign specific URLs to Tomcat. In general the structure of a JkMount directive is:

JkMount <URL prefix> <Worker name>

For example the following directives will send all requests ending in .jsp or beginning with /servlet to the “ajp13” worker, but jsp requests to files located in /otherworker will go to “remoteworker”.

JkMount /*.jsp ajp13

JkMount /servlet/* ajp13

JkMount /otherworker/*.jsp remoteworker

We can use the JkMount directive at the top level or inside <VirtualHost> sections of your httpd.conf file.

# bal1 is value from worker.properties. This is for mapping the worker to context root.<VirtualHost *:80>
JkMount /test_tomcat/* bal1
RewriteEngine On
</VirtualHost>

--

--

Khemnath chauhan
Khemnath chauhan

No responses yet