====== How to configure mod_proxy_ajp with Tomcat ? ====== uid=kerphi title=How to configure mod_proxy_ajp with Tomcat description=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 [...] category=software align=right ''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 [[http://tomcat.apache.org/connectors-doc/ajp/ajpv13a.html|AJP protocol]]. To respond to the question "[[http://tp.its.yale.edu/pipermail/cas/2008-July/009100.html|Why should I use mod_proxy_ajp rather than a classic mod_proxy ?]]", here is a small recap: * 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 ===== You just have to create the AJP connector in the ''conf/server.xml'' file like that: 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. Listen 1979 NameVirtualHost *:1979 ServerName localhost ErrorLog /var/log/apache2/ajp.error.log CustomLog /var/log/apache2/ajp.log combined AddDefaultCharset Off Order deny,allow Allow from all ProxyPass / ajp://localhost:8009/ ProxyPassReverse / ajp://localhost:8009/ * ''ProxyPass'' and ''ProxyPassReverse'' are classic reverse proxy directives used to forward the stream to another location. * ''ajp://...'' is the AJP connector location (your tomcat's server host/port) ===== What's the result ? ===== A web client will connect through HTTP to http://localhost:1979/ (supposing your apache2 server is running on localhost), the mod_proxy_ajp will forward you request transparently using the AJP protocol to the tomcat application server on ''localhost:8009''. {{tag>article computing proxy ajp apache tomcat}} ~~DISCUSSION~~