Serve Static Web Application Content with Apache
Audience
Streek developers who wish to build and deploy to Apache in front of JBoss-Tomcat.
Purpose
To serving of a web application's static content by the web server (Apache) rather than the application server (JBoss-Tomcat).
Prerequisites
- Successfully building copies of Streek and the web application whose static content is to be served by Apache.
- Installed and working JBoss-Tomcat.
- Installed and working Apache2 with mod_jk2 (cf. instructions in the Streek project site's HowTo section).
Serve Static Web Application Content with Apache
A preferred deployment for web applications is to serve static content with a web server rather than an application server. Streek is normally deployed to JBoss-Tomcat, and Apache is used to serve static content. The module mod_jk2 is used by Apache's httpd server to govern which client requests are passed through to the application server, and which are fulfilled by itself. Instructions for setting up Apache with mod_jk2 are available in the HowTo section of the Streek project site.
This HowTo document describes steps to take in order to build and deploy successfully to Apache in front of JBoss-Tomcat.
Create environment variable DEPLOY_WITH_APACHE
Ant tasks that copy static content to directories from which Apache serves are executed if and only if an environment variable on the building machine is set. The environement variable is DEPLOY_WITH_APACHE, which may be set to any value (e.g., "true").
Static Content Properties File
A properties file called static-content.properties is expected in the directory defined by the Ant property ${props.src.dir}. This Ant property, like many others that point to standard project directories, is defined in the properties files available in the ist-jxde tree available for CVS checkout (cf. antlib/properties/*.properties).
The static-content.properties file contains the directory in which static content is to be stored. Note that unix- and windows-style paths are defined by appropriately named properties in this file. During the build, Ant detects the operating system family on which it is being run, and chooses the appropriate path.
The properties in this file must point to a filesystem location where Ant can create the indicated directories if they do not already exist at build time, and later write to them.
Projcet Properties File
A properties file called ${code.name}-${deploy.mode}.properties is expected in the directory defined by the Ant property ${props.src.dir}. Note that both Ant properties code.name anddeploy.mode are defined in your web application's top level Ant script (probably build.xml).
Many critical properties are set here, including several that are central to service of static content from Apache:
- streek-static-root
- This is the directory within the root static-content directory pointed to by static-content.properties where static content will be copied. It's usually most transparent to set this property to match your deployed application's context root, e.g., courseweb-test
- help-url-root
- Help files, assuming they are static content, will be served by Apache. This property defines the directory in which the help/ directory will be found, including the streek-static-root prefix to that tree. For example, if the help files are HTML, this property might be set to /courseweb-test/html
Apache Alias for Static Content: static-content.inc
A file called static-content.inc is expected in the directory defined by the Ant property ${web.conf.dir}. This Ant property, like many others that point to standard project directories, is defined in the properties files available in the ist-jxde tree available for CVS checkout (cf. antlib/properties/*.properties).
This file, which is deployed in the root static content directory defined in static-content.properites, contains Apache configuration directives that alias expected application requests for static content to the location of that content on the filesystem. The file should look something like the following; note that the tokens delimited by "@" are substituted with appropriate values by Ant at build time.
<IfModule mod_alias.c> # # Note that if you include a trailing / on fakename then the server will # require it to be present in the URL. So "/icons" isn't aliased in this # example, only "/icons/". If the fakename is slash-terminated, then the # realname must also be slash terminated, and if the fakename omits the # trailing slash, the realname must also omit it. # Alias /@streek-static-root@/ "@htdocs-dir@/@streek-static-root@/" <Directory "@htdocs-dir@/@streek-static-root@"> Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all </Directory> </IfModule>
Configuring httpd.conf
The main Apache configuration file, at APACHE_HOME/conf/httpd.conf, must be configured to include the static-content.inc file described above. The Include directive that refers to this file should occur within an IfModule mod_jk2 block, and will look something like this (substituting for the filesystem location specified in the static-content.properties file described above).
<IfModule mod_jk2.c> # [...] Include c:/streek-webapp-minimal/htdocs/static-content.inc # [...] </IfModule>
Configuring workers2.properties
The Apache mod_jk2 configuration file, workers2.properties, must define those HTTP request URL patterns that will be referred to the application server, JBoss-Tomcat. Any requests other than these will be served by Apache (if Apache can't find them, it will return an error message to the client browser).
A sample workers2.properties file, including [uri:] directives for a sample application, can be viewed here.


