How to Use the mod_jk connector to integrate Apache2 and Tomcat 7

Source: Internet
Author: User

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:

  1. sudo apt-get install apache2
  2. sudo apt-get install tomcat7
  3. sudo apt-get install tomcat7-admin

Next, we will use the following command to create a test program:

  1. cd /var/lib/tomcat7/webapps
  2. sudo mkdir tomcat-demo
  3. sudo mkdir tomcat-demo/goodmoring
  4. sudo vim tomcat-demo/helloworld/index.jsp

Paste the following code to index. jsp:

  1. <HTML>
  2. <HEAD>
  3. <TITLE>Good Morning</TITLE>
  4. </HEAD>
  5. <BODY>
  6. <H1>Good Morning</H1>
  7. Today is: <%=new java.util.Date().toString() %>
  8. </BODY>
  9. </HTML>

After everything is complete, we will use the following command to install and configure mod_jk:

  1. sudo apt-get install libapache2-mod-jk

We need to use the following command to enable Tomcat's 8443 forwarding Port:

  1. sudo vim /etc/tomcat7/server.xml

Remove the following comments:

  1. <Connectorport="8009"protocol="AJP/1.3"redirectPort="8443"/>

Then, we will use the following command to create the workers. properties file for Apache:

  1. sudo vim /etc/apache2/workers.properties

Paste the following line:

  1. # Define 1 real worker using ajp13
  2. worker.list=worker
  3. # Set properties for worker (ajp13)
  4. worker.worker.type=ajp13
  5. worker.worker.host=localhost
  6. worker.worker.port=8009

Now we will use the following command to make Apache use this worker:

  1. sudo vim /etc/apache2/mods-available/jk.conf

We set the JkWorkersFile attribute to the following line:

  1. /etc/apache2/workers.properties

Finally, configure the URL that Apache sends to Tomcat for processing.

  1. sudo vim /etc/apache2/sites-enabled/000-default

The following lines are shown in the configuration file:

  1. <VirtualHost *:80>
  2. .......................................
  3. .......................................
  4. JkMount /tomcat-demo* worker1
  5. </VirtualHost *:80>

Run the following command to restart the service to check its functions:

  1. sudo /etc/init.d/tomcat7 restart
  2. 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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.