I need to setup apache so that any site.com/ANYTHING/servlet/ANYTHING goes over ajp into tomcat, but regular files will go through apache still.

I have been messing around with this to no avail

<LocationMatch "./*/servlet/*">
Order Allow,Deny
Allow from all
ProxyPass ajp://localhost:8009/
ProxyPassReverse /

This works at directing everything to our tomcat insance.

ProxyPass      /       ajp://localhost:8009/

Edit: I can verify the regex is correct but its still not sending it to proxy ajp. I also just reverified that ProxyPass / ajp://localhost:8009/ still works so I know ajp is good and I know the regex is good, but why is it still not working :\

RewriteRule ^(.*)/servlet/(.*)$ ajp://localhost:8009/$1 [P]
  • You need to match against the hostname as well as the path? – araqnid Jan 23 '11 at 23:17

I tend to use mod_rewrite for things like this, which allows you to apply a regular expression to the incoming URI. For example:

RewriteRule ^/((kaptcha|barcode)/view/(.*))$ ajp://$1 [P]

This proxies /kaptcha/view/nnnn to ajp:// The [P] at the end is a flag to indicate that the request is to be proxied, not redirected.

  • Can I do this if I don't know what all the sites will be and where they need to goto? They deploy and remove services fairly regularly. And all I know is site.com/something/serverlet/crazyweirdcodes/ need to goto tomcat just like that. – The Digital Ninja Jan 13 '11 at 20:13
  • RewriteRule ^/(()/servlet/(.))$ ajp://$1/servlet/$2 [P] Something like this? Edit: Bah its adding in stuff when i post in comments. But you get the idea – The Digital Ninja Jan 13 '11 at 20:14
  • Should be something like RewriteRule ^/(site\.com/(.+)/servlet/(.+)) ajp://localhost:8009/$1 [P] ... are you familiar with using regular expressions to match text? – araqnid Jan 13 '11 at 20:15
  • yes, looks like you've got the idea – araqnid Jan 13 '11 at 20:16

For the sake of simplicity, use mod_jk. It allows you to "mount" specific directories, so that you'll have something like this:

LoadModule jk_module modules/mod_jk.so
<IfModule mod_jk.c>
    JKMount       /some_context/*        ajp13
    JKMount       /another_context/*     ajp13

Alias /images /some/directory/served_by_apache

And so on.

This would not only simplify your configs, but would also provide you with the exact functionality you require.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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