## Can Jetty be run with mod_jk?

Jetty includes org.mortbay.http.ajp.AJP13Listener, which can be used instead of the normal SocketListener to received requests forwarded from a mod_jk module in apache or IIS.

The AJP13Listener has been tested with mod_jk from apache and mod_jk2 from apache2.

The normal jakarta/apache documentation can be used to configure mod_jk for Jetty. The documentation below was contributed for using mod_jk2 in apache2 and is included with the mod_jk2 source code.

### Using mod_jk2 and Jetty

by Simon Stewart<sms@lateral.net>

Jetty is a popular Open Source HTTP Server and Servlet container, written in 100% pure Java. It supports serving static content, servlets and JSPs, and is fast and lightweight. It is commonly used as an embedded HTTP and servlet container, notably by JBoss (a full featured J2EE environment)

Jetty's current developement branch is 4.1. This is working to enhance the performance of the server, as well as to improve its support for apache integration. To further this support, since 4.1.D2 Jetty has shipped with an AJP13 connector, meaning that it can communicate using the mod_jk and mod_jk2 apache modules in addition to working as a standalone server. This document aims to provide a guide for using this facility.

Normal, authenticated and SSL connections are all supported, so in theory, Jetty could be used as a "drop in" replacement for Tomcat.

In order to keep things as simple as possible, this document only considers apache2 and mod_jk2. This is the successor to mod_jk, and uses the same protocol, so using the older module should not cause any problems.

The process will be very similar to installing jk2 on any server, so if you are using IIS or iPlanet, simply follow the normal installation notes for jk2 on those platforms, ignoring any references to compiling the java code. Once the native side of the AJP13 connector is installed, skip to the section on "Configuring Jetty"

### Building

- Install apache, ensuring that DSO support is available.
- Install any version of Jetty from 4.1.D2 onwards.
- Copy build.properties.sample to build.properties
- Edit build.properties to taste. In particular it's important to set the path to apache2.
- Run "ant native" to build the native connectors for the detected servers (both jk and jk2) It is possible to use configure/make/dsp/apxs, but this way is simpler.
- Copy the created build/apache2/mod_jk2.so to your apache installation's module directory.

### Configuring Apache 2

On the native side, jk2 is configured using the workers2.properties file that is kept in apache's conf directory. Currently Jetty's AJP connector supports TCP/IP socket connections.

Perhaps the simplest way to explain things is with an example workers2.properties file:

    ---- workers2.properties

    # Example socket channel, override port and host.
    [channel.socket:localhost:8009]
    port=8009
    host=127.0.0.1

    # define the worker
    [ajp13:localhost:8009]
    channel=channel.socket:localhost:8009

    # Uri mapping. This says that any incoming connection to any file
    # under "/jetty/" should be handled the worker defined above

    [uri:/jetty/*]
    worker=ajp13:localhost:8009

    # The same, but for /demo
    [uri:/demo/*]
    worker=ajp13:localhost:8009

    ---- end worker2.properties

An "apachectl configtest" should report no errors.

You should configure the URI mappings to cover any installed webapps that you may have. The examples given here are for the demo apps that come with a fresh download of Jetty.

### Configuring Jetty

Jetty is easy to configure. At a bare minimum, all that needs to be done is to simply include the following fragment in Jetty's configuration file (typically found at etc/jetty.xml):

    <Call name="addListener">
      <Arg>
        <New class="org.mortbay.http.ajp.AJP13Listener">
          <Set name="port">8009</Set>
        </New>
      </Arg>
    </Call>

Once this is place, it should be possible to start Jetty and then (re)start apache. Check that everything works as expected by visiting port 8080 of your server with a web browser. If doesn't work then you have a problem with your Jetty config.

Assuming that you can connect properly to Jetty directly, it's time to connect using jk2. Check that your webserver is running as expected by pointing a browser at the homepage (for example, http://localhost/ ) If this works, attempt to visit one of the mapped URIs.

Congratulations!

### Jetty Config Options

The Jetty AJP13 connector has a compact set of configuration options. These are:

    ---- Jetty config options

    bufferSize          Size of the AJP13 data buffers
                        (default 8192)

    confidentialPort    The port to redirect to if a servlet security
                        constraint of CONFIDENTIAL is not met.
                        (default 0 : forbidden response).

    confidentialScheme  The scheme to use for confidential redirections
                        (default https)

    host                The host or IP interface to listen on.
                        (default 0.0.0.0 == all interfaces)

    identifyListener    Set the listener name as a request attribute
                        (default false)

    lingerTimeSecs      The socket linger time for closing sockets
                        (default 30)

    maxIdleTimeMs       Millisecs that a thread can be idle before the
                        thread pool shrinks.

    maxReadTimeMs       Millisecs that a read will block on a connection.

    maxStopTimeMs       Millisecs to wait when gently shutting down
                        listener.

    maxThreads          Maximum threads in threadpool for listener.

    minThreads          Minimum threads in threadpool for listener.

    name                Name of the listener.

    port                Port to listen on (8009)

    threadClass         The class to use for threads in the threadpool.

    ---- End Jetty config options

Most of these default to sensible values, and some of them (such as bufferSize) are unwise to fiddle with. An example of using these config options is given below.

    <Call name="addListener">
      <Arg>
        <New class="org.mortbay.http.ajp.AJP13Listener">
          <Set name="port">8009</Set>
          <Set name="minThreads">5</Set>
          <Set name="maxThreads">50</Set>
          <Set name="maxIdleTimeMs">30000</Set>
          <Set name="maxReadTimeMs">60000</Set>
        </New>
      </Arg>
    </Call>

JettyFaq