0

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 /
</LocationMatch>

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]
The Digital Ninja
  • 754
  • 4
  • 10
  • 25

2 Answers2

1

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://0.0.0.0:9019/media-webapp/$1 [P]

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

araqnid
  • 823
  • 5
  • 10
  • 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://0.0.0.0:9019/$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
0

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
</IfModule>

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.

Andrew M.
  • 10,982
  • 2
  • 34
  • 29