Configuring Apache2.2 mod_proxy_ajp with Tomcat
mod_proxy_ajp is an Apache module which can be used to forward a client HTTP request to an internal Tomcat application server using the AJP protocol. In this example I have used JSPWki as the example application running on a Windows server with Apache2.2 and Tomcat 5.5
Advantages of mod_proxy_ajp rather:
- You can gain a lot of flexibility (lot of the apache modules/features can be used especially “name-based virtual hosting”)
- Practical for those who need to support Java applications along with PHP / Perl … (only one apache server is needed)
- Certificates management is easier in apache configuration (this argument is a lot subjective)
- It’s not Tomcat’s main objective to serve http static resources (not optimized for that)
- Load balancing/cluster management is easier with an apache frontend
Tomcat configuration
We just have to create the AJP connector in the conf/server.xml file like that:
<Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
This line will enable AJP connections to the 8009 port of your tomcat server (localhost for example).
Apache2 configuration
One way (useful if this apache is a global front end) is to create a virtual host for this application.
ProxyPassandProxyPassReverseare classic reverse proxy directives used to forward the stream to another location.ajp://…is the AJP connector location (your tomcat’s server host/port)
# JSP Wiki DNS
<VirtualHost 10.1.1.170:80>
ServerName wiki.example.com
ServerAlias wiki
DocumentRoot “D:/Tomcat 5.5/webapps/JSPWiki/”
#DocumentRoot “D:/Apache2.2/htdocs/JSPWiki”
<Proxy *>
AddDefaultCharset Off
Order deny,allow
Allow from all
</Proxy>
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
</VirtualHost>
The following entries were made in server.xml on the Tomcat App Server :
<Host name=”wiki.example.com” debug=”0″
appBase=”D:/Tomcat 5.5/webapps”
unpackWARs=”true” autoDeploy=”true”>
<Alias>wiki</Alias>
<Context path= “” docBase=”D:/Tomcat 5.5/webapps/JSPWiki” debug=”1″/>
<Valve className=”org.apache.catalina.valves.AccessLogValve”
directory=”logs” prefix=”home_access_log.” suffix=”.txt”
pattern=”common” resolveHosts=”false”/>
</Host>
Under JSPWiki/WEB-INF/jspwiki.properties the Base URL was modified as follows :
jspwiki.baseURL=http://wiki/JSPWiki/
Comments
Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!





