Correctly configuring a Jetty Java Servlet container to be used through an Apache Web server via mod_jk

When deploying a JVM-based Web app usually so-called Java Servlet containers resp. application servers are used for the produciton system/environment. Probably the most popular and common Java server in this field is Apache Tomcat (and other even more feature-rich ones like JBoss or GlassFish). Apart from that, there's also Jetty which can be seen as a somewhat lightweight alternative. Nevertheless, there are some subtle differences to be taken into consideration when configuring it as opposed to Tomcat. The usual way to setup such a production system for a Java Web app is to use the Servlet container to serve the Web app and put so to speak in front of it an Apache Web server which handles the requests, hands them over to the container instance (e.g., Jetty or Tomcat) and receives its responses then (to say it in an a bit simplified way). Usually this is done via Apache's mod_jk module which enables communication between app server and Web server through the AJP13 protocol. What should be described and explained now is how to setup such a Java Web app production system ready for deployment in detail (mainly from a configuration perspective). The main focus shall be put at differences which are to be taken into account here between Jetty and Apache Tomcat.
1 answer

How to correctly configure a Jetty Servlet container to be used through an Apache Web server via mod_jk

Here are the basic/central steps to take.

  1. Install mod_jk (and mod_rewrite).
    sudo aptitude install libapache2-mod-jk libapache2-mod-rewrite
  2. Adjust jk.conf.
    sudo vi /etc/apache2/mod-available/jk.conf

    JkWorkersFile /etc/apache2/workers.properties
    JkLogFile /var/log/apache2/jk.log
    JkLogLevel error
    JkMount /jetty/* jetty
    JkOptions +ForwardURIEscaped
  3. Add JK instance to workers.properties.
    sudo vi /etc/apache2/workers.properties

    worker.list=jetty
    worker.jetty.port=8009
    worker.jetty.host=localhost
    worker.jetty.type=ajp13
  4. Enable mod_jk.
    sudo a2enmod jk
  5. Enable mod_rewrite.
    sudo a2enmod rewrite
  6. Add virtual host conf.
    sudo vi /etc/apache2/sites-available/app.example.com

    <VirtualHost *>
    ServerName app.example.com
    ...
    RewriteEngine on
    RewriteRule ^(.*) /jetty/app$1 [L,PT]
    ...
    </VirtualHost>
  7. Enable site.
    sudo a2ensite app.example.com
  8. Reload Web Server conf.
    sudo /etc/init.d/apache2 reload

Some mod_jk properties are not supported by resp. not working right with Jetty (as opposed to Tomcat), e.g.:
socket_timeout, socket_keepalive, connect_timeout

Have fun! :-)