Jetty 6.1.6 + Apache 2.2 + Web application
Jetty supports the use of a front-end HTTP server such as Apache as a front-end server for e.g. serving static files. Jetty is fast, small and full-featured Java-based HTTP server, especially useful for deploying Java-based web applications.
Here's a short walkthrough for configuring a Jetty with a Apache 2.2 front-end using AJP13. For more information see the original guide on Jetty website.
Prerequisites:
- Apache 2.2
- Jetty 6.1.x (downloadable here (http://dist.codehaus.org/jetty/))
- Your webapplication (later MyWebApp)
- Java 1.6
HTTPD_CONFIG_DIR = Apache configuration dir for external config files, e.g. /etc/httpd/conf.d
Steps:
- First install the JDK and Jetty to your preferred locations.
- Remove the testing stuff included in the distribution package (Optional):
rm contexts/test.xml
rm contexts/test-jndi.xml
rm contexts/javadoc.xml
rm -rf contexts/test-jndi.d
rm -rf contexts/test.d
rm -rf webapps/*
- Replace the following:
<Call name="addConnector">
<Arg>
<New class="org.mortbay.jetty.nio.SelectChannelConnector">
<Set name="host"><SystemProperty name="jetty.host" /></Set>
<Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
<Set name="maxIdleTime">30000</Set>
<Set name="Acceptors">2</Set>
<Set name="statsOn">false</Set>
<Set name="confidentialPort">8443</Set>
<Set name="lowResourcesConnections">5000</Set>
<Set name="lowResourcesMaxIdleTime">5000</Set>
</New>
</Arg>
</Call>
- With the following:
<Call name="addConnector">
<Arg>
<New class="org.mortbay.jetty.ajp.Ajp13SocketConnector">
<Set name="host">127.0.0.1</Set>
<Set name="port">8009</Set>
</New>
</Arg>
</Call>
- Next, copy the war file to your preferred location, e.g. /opt/mywebapp/MyWebApp.war
- Then create the a context file for Jetty in JETTY_DIR/contexts, named MyWebApp.xml
- This enables, for example, Jetty hot-deploy support. If this is not needed you could just extract the WAR to JETTY_DIR/webapps
- Contents:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<Set name="contextPath">/TarpChecking</Set>
<Set name="war">/FullPathTo/MyWebApp.war</Set>
<Set name="extractWAR">true</Set>
<Set name="copyWebDir">false</Set>
<Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
</Configure>
- Start Jetty with a designated init script (available in Jetty RPM distribution), or by running java -jar start.jar etc/jetty.xml in JETTY_DIR.
- Add the following file to HTTPD_CONFIG_DIR: mod_proxy_ajp.conf
- Contents (if no clustering is used... for clustering example, see the original guide.
LoadModule proxy_ajp_module /your_apache2_lib_dir/mod_proxy_ajp.so
ProxyPass /MyWebApp ajp://127.0.0.1:8009/MyWebApp
ProxyPreserveHost On
Note: The Apache 2 lib directory location depends on the Linux distribution / Apache build configuration used. For example, the default path for 64-bit OpenSUSE is /usr/lib64/apache2 and for CentOS 5 /usr/lib/httpd/modules
- Reboot Apache process, and your application should be accessible in http://yourserver/MyWebApp/
Disclaimer: This is not an official guide for installing Jetty. For official guides please refer to Jetty website.