tags:

views:

214

answers:

2

Using apache2 I want to set up an AJP proxy for a Tomcat server that maps an internal servlet URL to a completely different URL externally. Currently I am using the following configurations:

Apache2 configuration:

<IfModule mod_proxy.c>
    ProxyPreserveHost on
    ProxyPass /external_name ajp://192.168.1.30:8009/servlet_name
    ProxyPassReverse /external_name ajp://192.168.1.30:8009/servlet_name
</IfModule>

Note that external_name and servlet_name are different.

Tomcat 6 configuration:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

This however does not work. Apache seems to forward http requests to Tomcat. However the URLs and redirects returned by Tomcat are still using the original servlet_name and Apache does not map them to external_name.

Is this possible at all with AJP? If not can it be done using a plain http proxy instead?

A: 

Mapping different names between Apache and Tomcat can be quite tricky and depends much on how the web application builds its urls for the response.

Basically your setup is correct, but if your application uses its own servlet_name for redirects and urls ProxyPassReverse won't map them.

If you need this kind of setup have a look at mod_proxy_html (Apache 3rd party module) which will parse and rewrite also the contents, not only the url and response headers as mod_proxy.

jnas
A: 

( A late answer, but I just ran into this problem myself. )

It appears that ProxyPassReverse using ajp: doesn't work because the headers returned from a redirect don't have an ajp: URL in Location:, they have a http: URL. ProxyPassReverse just causes a rewrite of matching headers, and that string doesn't match what's being returned.

This should work (provided the Location: field uses that numerical address and not a host name.)

ProxyPreserveHost on
ProxyPass /external_name ajp://192.168.1.30:8009/servlet_name
ProxyPassReverse /external_name http://192.168.1.30/servlet_name

( You can use 'curl -I' to inspect the redirect headers and debug. )

See this note, or a more involved solution here using mod_proxy_html for rewriting the URLs in web pages as well.

Steven D. Majewski