Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

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: httpd.apache.org/docs/2.0/misc/rewriteguide.html –  REW Jul 1 '10 at 1:05

Your Answer

 
discard

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.