How to Use the mod_jk connector to integrate Apache2 and Tomcat 7
Apache is the most popular web server. It is usually used to receive and respond to client requests. It gets a URL, translates it into a file name (or static request), extracts the file from the local disk, and returns it over the Internet; or translates it into a program to execute it, then, the output is returned to the requester. If the web server cannot process or complete the request, it will return an error message.
In this article, we will list the features of Apache and how to use the mod_jk connector to integrate Tomcat 7 and Tomcat 8.
Apache features
Apache is the most popular web server. The reasons behind the popularity are as follows:
- It is a free tool and you can download and install it easily.
- It is open source, so you can view the source code, adjust it, optimize it, and fix errors and security vulnerabilities. You can also add new functions and modules.
- It can be used on a small website with only one or two pages, or a large website with thousands of pages, handling millions of regular visitor requests every month. It can process both static and dynamic content.
- Improved cache modules (mod_cache, mod_disk_cache, and mod_mem_cache ).
- Apache 2 supports IPv6.
Tomcat directory
$ {Tomcat_home} is the root directory of tomcat. Your tomcat installation should have the following sub-directories:
- $ {Tomcat_home} \ conf-place where different configuration files are stored
- $ {Tomcat_home} \ webapps-contains sample programs
- $ {Tomcat_home} \ bin-location where your Web server plug-in is stored
Mod_jk Module
Mod_jk has two acceptable methods: binary or source code. Depending on the platform of the web server you are running, there may be mod_jk that conforms to the binary version of your platform. If yes, we recommend that you use this.
The mod_jk module has been developed and tested on these platforms:
- Linux, FreeBSD, AIX, HP-UX, MacOS X, and Solaris should work on mainstream Unix platforms that support Apache 1.3 and/or 2.x.
- WinNT 4.0-i386 SP4/SP5/SP6a (it should work with other service packages), Win2K, WinXP and Win98
- Cygwin (you need apache server and autoconf/automake support tools)
- Netware
- I5/OS V5R4 (System I) with Apache HTTP Server 2.0.58. Make sure that the latest Apache PTF has been installed.
- From Tomcat 3.2 to Tomcat 8
The mod_jk requires two components:
- The mod_jk.xxx-Apache HTTP Server Module depends on your operating system. It may be mod_jk.so, mod_jk.nlm, or mod_jk.SRVPGM.
- Workers. properties-describes the host used by the Worker (Tomcat process) and the port used by the processor. Find the workers. properties file in the conf directory of the downloaded source code.
Like other modules of the Apache HTTP Server, mod_jk should be installed in the directory of the modules under your Apache server:/usr/lib/apache, And you should update your httpd. conf file.
Install
Before starting the installation, non-root users need to use the "sudo" privilege. Now we start to install Apache2 and Tomcat by using the following command:
sudo apt-get install apache2
sudo apt-get install tomcat7
sudo apt-get install tomcat7-admin
Next, we will use the following command to create a test program:
cd /var/lib/tomcat7/webapps
sudo mkdir tomcat-demo
sudo mkdir tomcat-demo/goodmoring
sudo vim tomcat-demo/helloworld/index.jsp
Paste the following code to index. jsp:
<HTML>
<HEAD>
<TITLE>Good Morning</TITLE>
</HEAD>
<BODY>
<H1>Good Morning</H1>
Today is: <%=new java.util.Date().toString() %>
</BODY>
</HTML>
After everything is complete, we will use the following command to install and configure mod_jk:
sudo apt-get install libapache2-mod-jk
We need to use the following command to enable Tomcat's 8443 forwarding Port:
sudo vim /etc/tomcat7/server.xml
Remove the following comments:
<Connectorport="8009"protocol="AJP/1.3"redirectPort="8443"/>
Then, we will use the following command to create the workers. properties file for Apache:
sudo vim /etc/apache2/workers.properties
Paste the following line:
# Define 1 real worker using ajp13
worker.list=worker
# Set properties for worker (ajp13)
worker.worker.type=ajp13
worker.worker.host=localhost
worker.worker.port=8009
Now we will use the following command to make Apache use this worker:
sudo vim /etc/apache2/mods-available/jk.conf
We set the JkWorkersFile attribute to the following line:
/etc/apache2/workers.properties
Finally, configure the URL that Apache sends to Tomcat for processing.
sudo vim /etc/apache2/sites-enabled/000-default
The following lines are shown in the configuration file:
<VirtualHost *:80>
.......................................
.......................................
JkMount /tomcat-demo* worker1
</VirtualHost *:80>
Run the following command to restart the service to check its functions:
sudo /etc/init.d/tomcat7 restart
sudo /etc/init.d/apache2 restart
Summary
In this article, we show you how to configure and install Apache2 and Tomcat7 using the mod_jk connector.
Via: http://www.unixmen.com/integrate-apache2-tomcat-7-using-mod_jk-connector/
Author: anismaj Translator: geekpi Proofreader: wxy
This article was originally translated by LCTT and launched with the Linux honor in China
This article permanently updates the link address: