Linux – need help in redirect from Apache to Tomcat with mod_proxy_ajp

apache-2.2linuxmod-proxy-ajptomcat

Im using mod_proxy_ajp to redirect from Apache to Tomcat. Apache is runnig on port 80 and tomcat ajp connector set on port 8081. here is my virtual host configuration:

<virtualHost *:80>
   ServerName www.example.com
   ProxyRequests Off
   ProxyPreserveHost On

   <Proxy *>
      AddDefaultCharset Off
      Order deny,allow
          Allow from all
   </Proxy>

   ProxyPass / ajp://localhost:8081/example/
   ProxyPassReverse / ajp://localhost:8081/example/

   <Location />
    Order allow,deny
    Allow from all
   </Location>
</VirtualHost>

The problem is when i type url www.example.com ( example is in tomcat webapp directory) only the title of example app loads and the browser stop loading and nothing happens.
any idea?
Thanks and sorry for my poor english

Best Answer

In the default configuration, the 8080 port serves HTTP content, and AJP is served using the 8009 port. You can confirm this in tomcat's server.xml file, an example:

<Executor name="tomcatThreadPool" 
          namePrefix="catalina-exec-"
          maxThreads="150" 
          minSpareThreads="4"/>

<Connector executor="tomcatThreadPool"
           port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

<Connector executor="tomcatThreadPool"
           port="8009" protocol="AJP/1.3"
           connectionTimeout="20000"
           URIEncoding="UTF-8"
           redirectPort="8443" />

mod_proxy_ajp does not require a ProxyPassReverse directive, so you can simply replace:

ProxyPass / ajp://localhost:8081/example/
ProxyPassReverse / ajp://localhost:8081/example/

with:

ProxyPassMatch ^/(example)(.*) ajp://localhost:8009/$1$2 ttl=120 ping=1

in the Apache configuration. Use the appropriate port for AJP.