Httpd – proxy_ajp wildcards

ajpapache-2.2httpdmod-proxy-ajp

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]

Best Answer

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.

Related Topic