Freebsd Install mod_jk module Apache Tomcat

Mod_jk is an Apache module or connector that connects the Apache Tomcat servlet container with web servers such as Apache, IIS, etc. Mod_jk is a complete replacement for the old mod_jser module that handles communication between Tomcat and an HTTP server using the Apache JServ protocol. The Apache mod_jserv module is a legacy bridge between Java and Apache.

The Apache mod_jk module is a bridge between Apache Web Server and Tomcat Server. Web requests over port 80 are handled by Apache and then Java Servlet and JSP requests are forwarded to the appropriate place such as the Tomcat server. This article will explain how to configure mod_jk with Apache http and Tomcat servers. The Apache Tomcat connector allows using the Apache httpd server as a front-end for Apache Tomcat applications.

To run Tomcat and Apache simultaneously, Apache needs to load an “adapter” module, which uses a specific protocol, such as the Apache JServ Protocol (AJP), to communicate with Tomcat, over another TCP port (port 8009 is the default configuration in the server.xml file in under the Tomcat server). When the Apache server receives an HTTP request, it checks whether the request belongs to the Tomcat server and if YES, it forwards it to Tomcat.

AJP is a wired protocol and an optimized version of the HTTP protocol, which allows a standalone http server, such as Apache to talk to Tomcat. For years, the Apache http server was much faster than Tomcat at serving static content. The idea here is to let the Apache http server serve static content whenever possible, but use the Apache http server as a proxy to the Tomcat server for Tomcat related content.

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. Supported web servers are:
  1. Apache HTTP Server with a plugin (module) called mod_jk.
  2. Microsoft IIS with a plugin (extension) called ISAPI redirector (or simply redirector).
  3. iPlanet Web Server with a plugin called NSAPI redirector. iPlanet Web Server was previously known by various names, including Netscape Enterprise Server, SunOne Web Server, and Sun Enterprise System web server.
In all cases, the plugin uses a special protocol called Apache JServ Protocol or simply AJP to connect to the backend. Backends known to support AJP are Apache Tomcat, Jetty and JBoss. Although there are 3 protocol versions, ajp12, ajp13, ajp14, most installations only use ajp13. Older ajp12 does not use persistent connections and is deprecated, newer versions of ajp14 are still experimental. Sometimes ajp13 is called AJP 1.3 or AJPv13, but we more often use the name ajp13.

Most of the plugin features are the same for all web servers. Some details vary by web server. Documentation and configuration are divided into general sections and web server specific sections.

1. Installing mod_jk on FreeBSD

mod_jk merupakan bagian dari sistem ports "www" pada FreeBSD. Untuk melakukan instalasi mod_jk sangat mudah sekali. Kita hanya megnetikkan perintah di bawah ini untuk menginstall mod_jk.

root@ns1:~ # cd /usr/ports/www/mod_jk
root@ns1:/usr/ports/www/mod_jk #
make install clean

Well, after the mod_jk module has been installed, now check whether the module is active or not. The mod_jk module is in the "httpd.conf" file, open the /usr/local/etc/apache24/httpd.conf file and look for the script "LoadModule jk_module libexec/apache24/". To activate it, remove the "#" sign in front of the script, if the "#" sign is not there it means the mod_jk module can be used.

2. Mod_jk configuration

Even though mod_jk can be used, the module is not yet active, so how do I activate it? The following are the steps on how to activate the mod_jk module.

a. Create a mod_jk.conf file

We will place the mod_jk.conf file in the /usr/local/etc/apache24/Includes folder, in the /usr/local/etc/apache24/Includes/mod_jk.conf file, enter the script below.

root@ns1:~ # cd /usr/local/etc/apache24
root@ns1:/usr/local/etc/apache24 #
touch Includes/mod_jk.conf
root@ns1:/usr/local/etc/apache24 #
chmod +x Includes/mod_jk.conf
root@ns1:/usr/local/etc/apache24 #
ee Includes/mod_jk.conf
# Replace jsp-hostname with the hostname of your JSP server, as
# specified in
<IfModule mod_jk.c>
JkWorkersFile etc/apache24/
JkLogFile /var/log/jk.log
JkShmFile /var/log/jk-runtime-status
JkLogLevel error

# Sample JkMounts. Replace these with the paths you would
# like to mount from your JSP server.
JkMount /*.jsp jsp-hostname
JkMount /servlet/* jsp-hostname
JkMount /examples/* jsp-hostname

The script above is used to create the /usr/local/etc/apache24/Includes/mod_jk.conf file, and the orange script is the script CONTENTS of the /usr/local/etc/apache24/Includes/mod_jk.conf file.

After that, we create a file called "" which we will place in the /usr/local/etc/apache24 folder. Follow the steps below to create a script in the /usr/local/etc/apache24/ file. In this article, use the "ee" editor to include the script in the /usr/local/etc/apache24/ file.

root@ns1:/usr/local/etc/apache24 # touch /usr/local/etc/apache24/
root@ns1:/usr/local/etc/apache24 #
chmod +x /usr/local/etc/apache24/
root@ns1:/usr/local/etc/apache24 #
ee /usr/local/etc/apache24/
# Incredibly simple file, intended for connecting
# to one host, via AJP13. See the tomcat documentation for
# information on more exotic configuration options.
# Change jsp-hostname to the hostname of your JSP server.

root@ns1:/usr/local/etc/apache24 # chown -R www:www /usr/local/etc/apache24/

Now we create a log file and we name the user group "www:www".

root@ns1:~ # touch /var/log/jk.log
root@ns1:~ #
touch /var/log/jk-runtime-status
root@ns1:~ #
chown -R www:www /var/log/jk.log
root@ns1:~ #
chown -R www:www /var/log/jk-runtime-status

The next step is to activate the mod_jk module on the Tomcat server. Open the file /usr/local/apache-tomcat-9.0/conf/server.xml, and look for the following script.

<!-- dan -->
<Connector protocol="AJP/1.3"

To activate the mod_jk module, remove the "<!--" and "-->" signs in the script, so the result will be as below.

<Connector protocol="AJP/1.3"

Then we restart the Apache24 application.

root@ns1:~ # service apache24 restart
root@ns1:~ #
service tomcat9 restart

This tutorial only shows a small part of how to configure and use the mod_jk module on Apache24 servers and Tomcat9 servers. You can learn more from the official documents on the websites of both applications.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post