views:

1432

answers:

3

As a result of horrible, horrible errors, we've changed how we connect Apache to Tomcat. We were using mod_jk:

JkMount /path ajp13

Now we're using mod_proxy_ajp:

ProxyPass /path ajp://localhost:8009/path
ProxyPassReverse /path ajp://localhost:8009/path

However, there's a feature that JkMount offered but ProxyPass doesn't: the ability to select on file types. This made it possible to proxy html files, but not images - in other words, to let the nice fast Apache serve the static stuff, and resorting to the slow Tomcat only for the dynamic stuff.

JkMount /*.html ajp13

Is there any way of achieving this with ProxyPass? Possibly using a surrounding <Location> directive or something like that?

+3  A: 

Use ProxyPathMatch:

ProxyPathMatch ^/(path/.*\.html)$ ajp://localhost:8009/$1

Edited: Marcus Downing’s correction

kmkaplan
Are there performance implications of using a regular expression?
Marcus Downing
Regular expression have some performance issues when you have overcomplex expressions. For this kind of regular expression it’s ok.
kmkaplan
+1  A: 

Not your issue but something to watch out for using this configuration. While using apache mod_proxy to connect to tomcat my error log was showing dropped connections under moderate load. Adding this to httpd.conf solved my problems.

SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1
jms
Can you explain what these do?
Marcus Downing
turns off keep alive connections and makes the request use http 1.0 instead of 1.1
jlintz
Correct. I believe the original errors messages where a symptom of a different problem but I was receiving them on both internal and 3rd party apps on the same tomcat instance. Anyhow this these changes cleared up the error log.
jms
+1  A: 

kmkaplan's post is the right answer, but it gave me the error:

Syntax error on line 32 of .../httpd-vhosts.conf:
ProxyPass Unable to parse URL

It worked when I changed the directive to read:

ProxyPathMatch ^/(path/.*\.html)$ ajp://localhost:8009/$1

I can only assume that putting the $1 right next to the port number 8009 was confusing it.

Marcus Downing