Skip to content. | Skip to navigation

Navigation

Personal tools

Web Applications

This guide shows how to build several web applications and servers. The basic concept is that of an Apache 2 webserver fronting several application servers (such as Apache Tomcat and Plone). We'll be hosting several domains and handling SSL. To avoid unnecessary rebuilding we'll attempt to reuse existing infrastructure.

Apache Tomcat

A Java servlet engine

We all want to run Java servlets, don't we?

Here we'll prepare the system to allow us to manipulate the running configuration from remote sites using ant

Note

  1. apache-tomcat extracts AS IS
  2. extract with GNU tar
cd /usr/local
gzcat .../apache-tomcat-5.5.12.tar.gz | gtar xf -

If you have any pre-existing servlet files you'll need to edit the configuration file (.../conf/server.xml) will something not dissimilar to:

<Context path="*URL*" docBase="*filesystem path*" debug="0" reloadable="true">
</Context>

Inside the <Host> section (at the end!).

Where you would replace

*URL*
with the path part of the URL people will access this with, for example /myservlet which would be accessed as http://*hostname*/myservlet.
*filesystem path*
with the physical location of the directory containing the servlets code, for example /www/apache2/*hostname*/myservlet-dir.

For ant, you need to add appropriate users (and passwords) to .../conf/tomcat-users.xml with the manager role.

Finally, we'll be running all this as a particular user, in this case catalina for historical reasons (remembering to give that user permission to modify the directory hierarchy!):

su
groupadd catalina
useradd -g catalina catalina
passwd -l catalina

chown -R catalina:catalina /usr/local/apache-tomcat-5.5.12

Note

This should be an SMF service!

cat <<EOF >/etc/init.d/catalina
#! /sbin/sh

TOMCAT_HOME=/usr/local/${PWD##*/}

case "\$1" in
*)

    su catalina -c "\${TOMCAT_HOME}/bin/catalina.sh \$@"

    ;;
esac
EOF
chmod +x /etc/init.d/catalina
ln /etc/init.d/catalina /etc/rc3.d/S60catalina
ln /etc/init.d/catalina /etc/rc3.d/K60catalina

We need to tell Apache where we are. In server.xml there is an AJP 1.3 connector defined which by default listens on port 8009. That's what mod_jk will be trying to talk to.

In our Apache configuration file (/www/apache2/etc/httpd.conf) we need to declare some mod_jk facts:

<IfModule mod_jk.c>
  JkWorkersFile /www/apache2/etc/workers.properties
  JkLogFile     /www/apache2/logs/mod_jk.log
  JkLogLevel    info
</IfModule>

and in turn, in the workers.properties file we've just declared we need to give the low down on exactly what Tomcats are listening where:

worker.list             = worker1

# entries are should match the tomcat setup!
worker.worker1.type     = ajp13
worker.worker1.host     = localhost
worker.worker1.port     = 8009

where

worker1
is an arbitrary name we give to, in this case, our solitary Tomcat server.

We could define several workers, possibly all on the same box (on different ports, in that case!) which might be used as fallbacks in case of failure or, if they were on different boxes they might be used for load balancing (and fallbacks!).

Document Actions