Helma logo
helma.org » Home > docs > howtos > Connecting Apache and Helma via mod_jk (AJP13)

Connecting Apache and Helma via mod_jk (AJP13)

A how-to guide for configuring Helma's built-in Jetty AJP13 support.

The following instructions guide you through the work necessary to access Helma through an Apache web server via the Tomcat AJP13 protocol. With the integration of Jetty this task has become much easier than it used to be. It is no longer necessary to install the full Apache Tomcat package. It is possible however to run both Tomcat and Helma/Jetty behind the same Apache server - configuration may even become easier if you already have mod_jk installed!

  1. Get a precompiled mod_jk module for your platform and Apache release. If no precompiled binaries are available for your platform, you should be able to build mod_jk from source with these commands:

    $ tar xzf jakarta-tomcat-connectors-jk-XXX-src.tar.gz
    $ cd jakarta-tomcat-connectors-jk-XXX-src/jk/native/
    $ sh buildconf.sh
    $ ./configure --with-apxs=/usr/sbin/apxs
    $ make

    Copy the module to where the other Apache modules are. If you are on Unix, you'll probably have to set the execute permission on the file.

  2. Activate the AJP13 port in your Helma start script. This is most easily done by uncommenting the line AJP13_PORT=8009 in start.sh. You may or may not want to activate the other ports.

  3. Create a file called workers.properties with the following content.

    # Definition of Helma Ajp13 worker. Note that adding whitespace
    # chars to workers.properties file will stop mod_jk from working 
    # (contrary to Helma, which doesn't mind)
    #
    worker.list=helma
    worker.helma.port=8009
    worker.helma.host=localhost
    worker.helma.type=ajp13
    This file may either be in your Helma installation directory or in the place where your Apache configuration files are.

  4. Open the main Apache configuration file (usually /etc/httpd/httpd.conf) in your favorite editor and add the following lines (see notes below on where to place the individual lines):

    ...
    
    LoadModule    jk_module  libexec/mod_jk.so
    
    ...
    
    AddModule     mod_jk.c
    
    ...
    
    # Configure mod_jk
    JkWorkersFile /usr/local/helma/workers.properties
    JkLogFile     /var/log/httpd/mod_jk.log
    JkLogLevel    error
    
    ...
    
    # Mounting /antville/* on the default host.
    JkMount /antville/* helma
    
    ...
    
    # Mounting /gong/* to a virtual host.
    <VirtualHost 10.0.0.2:80>
      ...
      JkMount /gong/* helma
    </VirtualHost>
    A few notes:
    • Put the LoadModule where all the other LoadModule directives are. If you want to use the Apache Rewrite module in combination with mod_jk, be sure to load mod_jk before mod_rewrite. In most cases it is the best to place mod_jk somewhere near mod_cgi.
    • The AddModule should be placed among the other AddModules in the same relative order to the other modules as the LoadModule directive.
    • Place the JkWorkersFile directive after the AddModules block. Be sure to set the path to workers.properties file to the location you chose in step 4!

  5. Finally, edit the apps.properties file in your Helma installation directory so that the application mountpoints match the ones you used in the Apache setup. This may not be necessary if the mountpoint equals the application name. However, it would look like this:

    antville
    antville.mountpoint = /antville
    
    gong
    gong.mountpoint = /gong
    

This should be it. You should now be able to access your Helma applications through Apache. In our case, the applications would be at http://localhost/antville/ and http://virtual.domain.com/gong/.

Note that for now you need the trailing slashes! Check out the mod_rewrite section below for how to create nicer URLs.

Nicer URLs with Apache mod_rewrite

mod_rewrite is an Apache module for rewriting URLs of incoming requests before they're being served. You can see from the documentation that mod_rewrite is incredibly flexible and powerful. Below is a simple example of how mod_rewrite can be used to rearrange the URL space of a Helma application served by Apache.
<VirtualHost 10.0.0.2:80>
  ...
  # mount Helma application at /gong
  JkMount /gong/* helma

  # activate the rewrite module
  RewriteEngine on

  # pass through requests to /images and /static directories
  RewriteRule ^/images(.*) /images$1 [L]
  RewriteRule ^/static(.*) /static$1 [L]
  # pass through requests ending with *.html
  RewriteRule ^/(.*\.html)$ /$1 [L]

  # everything else is handled by our gong application
  RewriteRule ^/(.*) /gong/$1 [L,PT]

</VirtualHost>
You'll have to change the baseUri property in apps/gong/app.properties to "/" in order to make Helma generate correct URLs.

Note the [L] and [L,PT] at the end of the RewriteRules. L stands for "last" and means that no more RewriteRules will be evuated if the current pattern matches. PT stands for "pass-through" and makes sure the request is passed to the mod_jk module, which will eventually serve the request.

If mod_rewrite does not work in combination with mod_jk, make sure you loaded mod_jk before mod_rewrite (see notes above).


Up: Deployment Guides
Previous: Cache mechanism Next: LAMTHA

... comment


Page last modified on 2006-03-20 13:37 by hns

 
jonno, Saturday, 21. January 2006, 08:13
Thank you!
Thank you, thank you, thank you for such great documentation. I'm not actually using Helma at all, but Google led me here after an hour of tearing my hair out and trying to integrate Apache and Tomcat using mod_rewrite and mod_jk. Everything was in place except for the mod_jk/mod_rewrite ordering in LoadModule/AddModule directives. Since I'm no expert on Apache internals it would have taken me ages to work this out.

Jon

... link  


... comment