Apache-Tomcat integration on Ubuntu server

13 / Feb / 2008 by Deepak 9 comments

Follow the steps mentioned below to integrate Apache with Tomcat on an Ubuntu system. The steps assume that Apache and Tomcat are already installed and working fine independently.

  • Install Apache module for tomcat

sudo apt-get install libapache2-mod-jk

  • Create a file by the name “worker.properties” in /etc/apache2 directory. Sample worker.properties file below

workers.tomcat_home=/opt/servers/tomcat5.5
workers.java_home=/opt/java/jdk1.5
ps=/
worker.list=worker1
worker.default.port=8009
worker.default.host=localhost
worker.default.type=ajp13
worker.default.lbfactor=1

  • Add the following line to your site configuration file (/etc/apache2/sites-available/dellServer)

jkMount /* worker1

  • Add the following lines to the end of your /etc/apache2/apache2.conf file

LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile /etc/apache2/workers.properties
# Where to put jk logs
JkLogFile /tmp/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

Tag -

apache tomcat
FOUND THIS USEFUL? SHARE IT

comments (9)

  1. jim c cott

    Good day! Do you use Twitter? I’d like to follow you if that would be okay. I’m definitely enjoying your blog and look forward
    to new posts.

    Reply
  2. Sam

    Thanks much! Worked like a charm under Ubuntu.

    One change I made, for ubuntu concistency’s sake, was to move the line
    LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
    into apache2/mods-available/jk.load

    Next step for me is to tweak this into serving two tomcat instances hosting two appplications I want to keep in separate JVMs, as well as serve some static pages straight from apache without going through tomcat. Should be easy enough after this nicely done quick-start.

    Reply
  3. Gus

    I read with great interest your document. I been trying to make the connection for two days. Read many articles and documentation. I try you advice to the letter. Still it does not work for me. I’m Using Ubuntu Server and Tomcat v6. I do not know what else to do. The module is there, and working fine, Apache, and Tomcat are also working fine (but not together) what can I do to check where is the problem? Any suggestions?

    Reply
  4. Stephen Howe

    Modules are not “officially” loaded into apache this way in ubuntu and debian.
    The modules are either compiled or loaded at run-time.
    To see what modules are compiled in, use the command

    apache2 -l

    To load modules at run-time, two lines are added to the apache2.conf file located in the directory /etc/apache2/ in ubuntu.
    These are as follows:-
    # Include module configuration:
    Include /etc/apache2/mods-enabled/*.load
    Include /etc/apache2/mods-enabled/*.conf

    As you can see, apache loads any files ending with .load first and .conf after, in /etc/apache2/mods-enabled/.

    To make apache 2 load additional mods, you can manually create links from the directory mods-enabled to the directory mods-available for both “load” and “conf” files of the mod you need to load or you can use the command a2enmod which does it automatically.

    hence, in ubuntu or debian, you should actually add

    LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so
    # Where to find workers.properties
    JkWorkersFile /etc/apache2/workers.properties
    # Where to put jk logs
    JkLogFile /tmp/mod_jk.log
    # Set the jk log level [debug/error/info]
    JkLogLevel info
    # Select the log format
    JkLogStampFormat “[%a %b %d %H:%M:%S %Y] ”
    # JkOptions indicate to send SSL KEY SIZE,
    JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
    # JkRequestLogFormat set the request format
    JkRequestLogFormat “%w %V %T”

    to your jk.conf in /etc/apache2/mods-available/ directory and then check that the load command in jk.load is pointing to the right place
    i.e. mod_jk.so in the directory /usr/lib/apache2/modules

    Reply
  5. AJ

    I have two websites on the same tomcat and apache. The rule JKMount /* just sends everything to tomcat. How do I configure workers.properties or httpd.conf to power two websites using mod_jk?

    Reply
  6. Amit

    Hi there,
    This is a very useful tutorial. I searched a lot for making apache work with my tomcat, but couldnt make it work. But after reading this article, it was just a matter of minutes. and finally i got my apache work with tomcat.

    I really appreciate ur writing and wish u good luck. keep writing.

    Reply

Leave a comment -