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

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]
share|improve this question
    
You need to match against the hostname as well as the path? –  araqnid Jan 23 '11 at 23:17

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
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

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.

share|improve this answer

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.