开发者

AJP proxy that maps internal servlet name to a different external name

开发者 https://www.devze.com 2022-12-20 05:23 出处:网络
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 t开发者_JAVA百科he following configurat

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 t开发者_JAVA百科he 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?


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.


( 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.


Additionally to the answer from Steven D. Majewski there is one more problem. If the target application uses the request host name to create a redirect (302 Moved Temporarily), it won't work with multiple host names. One must create multiple configurations for every name, like this:

ProxyPassReverse /external_name http://server.com/servlet_name
ProxyPassReverse /external_name http://server.org/servlet_name
ProxyPassReverse /external_name http://server.co.uk/servlet_name

Actually the ProxyPreserveHost on must solve this issue and replace the HOST header in the incoming requests with the address or IP specified in ProxyPass. Unfortunately it seems to be the ProxyPreserveHost doesn't work with ajp connectors. The tomcat in my configuration still received the host name got from browser instead replacing it with 192.168.1.30. As result the browser based redirects still didn't work for every name.

Following configuration didn't work as well :-(

# NOT WORKING !!!
ProxyPassReverse /external_name http://%{HTTP_HOST}/servlet_name 

The workaround was using http instead of ajp.

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

Did somebody investigate it deeply?


For me, this seemed to cause problems:

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

While this seemed to work:

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

I don't know why but it just did.

0

精彩评论

暂无评论...
验证码 换一张
取 消