Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

OK this question is asked all the time I know: "What's the best way to connect Tomcat through apache". But I still haven't found a definitive answer and maybe there isn't one, but I'm just looking for a viable, high performance setup. So much of the documentation I've read references articles from 2005 and older. I'm looking for a 2010 solution :)

I have a current setup (not created by me) that uses mod_rewrite to rewrite all traffic from apache to tomcat using:

RewriteRule ^(.*) ajp://localhost:8009$1 [P,L]

We have one app as the ROOT app in tomcat. So right now I'm using mod_rewrite to send requests over ajp (is this different from mod_proxy_ajp??). Are there any reasons why this might be less than satisfactory?

Also, I'm looking to get Apache to serve up static assets to take some load off Tomcat, also so I can easily use mod_expires/deflate etc... I'm unsure of how to do this.

I have an 'assets' (ie. js/css) and 'images' folder in the webroot (same directory as WEB-INF) so I'm assuming I need some sort of match on /images and /assets that says "don't pass this on to Tomcat" ??

Any help/suggestions/comments on the current setup are greatly appreciated.

btw i'm using:
apache2 - 2.2.9-10
Tomcat - 5.5.29

share|improve this question
up vote 0 down vote accepted

The P in your rewriterule is Proxy

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !^(images|assets)
RewriteRule ^(.*) ajp://localhost:8009$1 [P,L]
share|improve this answer
just had to add a \/ ie !^\/(images|assets) to that as I use absolute references. thx! – brad Jul 5 '10 at 14:32

If you would like say, things under the path http://localhost/static/* to be served up from Apache, then you can set a RewriteCond before your rule to capture everything that doesn't have the URI as /static/* and forward on the Tomcat via AJP, essentially leaving /static/* alone to be served out from DocRoot or an Alias, etc.

For example:

RewriteCond %{REQUEST_URI} !\/static\/.* [NC]
RewriteRule ^(.*) ajp://localhost:8009$1 [P,L] 
share|improve this answer
I am going to see if I can't get you a little sample. In the mean time, the Apache ModRewrite Guide is great: – REW Jul 1 '10 at 1:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.