将内部 servlet 名称映射到不同的外部名称的 AJP 代理
我想使用 apache2 为 Tomcat 服务器设置一个 AJP 代理,将内部 servlet URL 映射到外部完全不同的 URL。目前我使用以下配置:
Apache2 配置:
<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>
请注意 external_name
和 servlet_name
是不同的。
Tomcat 6 配置:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
但这不起作用。 Apache似乎将http请求转发到Tomcat。 然而,Tomcat 返回的 URL 和重定向仍然使用原始的 servlet_name
,并且 Apache 不会将它们映射到 external_name
。
AJP 可以做到这一点吗?如果不能,可以使用普通的 http 代理来完成吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 Apache 和 Tomcat 之间映射不同的名称可能非常棘手,并且很大程度上取决于 Web 应用程序如何构建响应的 url。
基本上您的设置是正确的,但如果您的应用程序使用自己的 servlet_name 进行重定向和 url,ProxyPassReverse 将不会映射它们。
如果您需要这种设置,请查看 mod_proxy_html (Apache 3rd party module),它将解析并将内容重写为 mod_proxy,而不仅仅是 url 和响应标头。
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.
(一个迟到的答案,但我自己也遇到了这个问题。)
似乎使用 ajp: 的 ProxyPassReverse 不起作用,因为从重定向返回的标头在 Location: 中没有 ajp: URL,它们有一个 http:网址。 ProxyPassReverse 只是导致匹配标头的重写,并且
该字符串与返回的内容不匹配。
这应该可行(前提是位置:字段使用该数字地址
而不是主机名。)
(您可以使用“curl -I”来检查重定向标头并进行调试。)
请参阅 此注释,或更复杂的 这里的解决方案使用mod_proxy_html
也用于重写网页中的 URL。
( 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.)
( 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 的回答之外,还有一个问题。如果目标应用程序使用请求主机名创建重定向(302 临时移动),则它将无法使用多个主机名。必须为每个名称创建多个配置,如下所示:
实际上,
ProxyPreserveHost on
必须解决此问题,并将传入请求中的 HOST 标头替换为ProxyPass
中指定的地址或 IP >。不幸的是,ProxyPreserveHost
似乎不适用于 ajp 连接器。我的配置中的 tomcat 仍然接收从浏览器获取的主机名,而不是将其替换为192.168.1.30
。因此,基于浏览器的重定向仍然不适用于每个名称。以下配置效果不佳:-(
解决方法是使用 http 而不是 ajp。
有人深入研究过吗?
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:
Actually the
ProxyPreserveHost on
must solve this issue and replace the HOST header in the incoming requests with the address or IP specified inProxyPass
. Unfortunately it seems to be theProxyPreserveHost
doesn't work with ajp connectors. The tomcat in my configuration still received the host name got from browser instead replacing it with192.168.1.30
. As result the browser based redirects still didn't work for every name.Following configuration didn't work as well :-(
The workaround was using http instead of ajp.
Did somebody investigate it deeply?
对我来说,这似乎引起了问题:
虽然这似乎有效:
我不知道为什么,但它确实有效。
For me, this seemed to cause problems:
While this seemed to work:
I don't know why but it just did.