1

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

brad
  • 492
  • 1
  • 10
  • 22

2 Answers2

1

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] 
REW
  • 223
  • 2
  • 9
  • I am going to see if I can't get you a little sample. In the mean time, the Apache ModRewrite Guide is great: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html – REW Jul 01 '10 at 01:05
0

The P in your rewriterule is Proxy

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