ProxyPassMatch与ProxyPassReverse

ProxyPassMatch与ProxyPassReverse

本文介绍了ProxyPassMatch与ProxyPassReverse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,
我们正试图安装的Apache反向代理的以下情形:


  • 传入的请求采取的形式 http://foo.com/APP/v1/main.html

  • 某些服务器的URL将引用不同的版本,比方说, http://foo.com/APP/v2/main.html

  • 上游负载平衡器(HAProxy的)将请求发送到正确的服务器,这将有一个Apache2的反向代理面向一个JBoss服务器。

  • 当请求在Apache 2的显示出来就会有像 /APP/v1/main.html 请求路径

  • 我们希望它(反向)代理到的http://本地主机:8080 / AppContext / main.html中不论的版本在URL(V1,V2等)片段。

我一直在努力做到这一点,像这样:

ProxyPassMatch ^ / * / * APP / $ HTTP?(*)://本地主机:8080 / AppContext / $ 1
ProxyPassReverse / APP的http://本地主机:8080 / AppContext

我的问题是:


  1. 是我使用 ProxyPassMatch 是否正确?

  2. 我的 ProxyPassReverse 是静。我如何使它意识到潜在的可变填充 / APP
  3. 之后

感谢您的任何见解。

-Raj


解决方案

您正在接近,尝试改变正则表达式稍微占版本片段:

ProxyPassMatch ^ / * / * APP / V [0-9] + / $ HTTP(*)://本地主机:8080 / AppContext / $ 1

ProxyPassReverse 主要是确保重写上即时通过代理的应用程序提供的位置的响应头字段。因此,当它返回一个301重定向,比方说,的http://本地主机:8080 / AppContext /东西,阿帕奇知道将其更改为 / APP / V1 /东西所以代理的背后信息也不会暴露。因为你在反向代理使用动态URL,你有几个选择这里。您可以将其发送到HAProxy的负载均衡器(不知道在哪里这是给你的),或者你可以选择一个,并希望最好的结果。例如,如果你有一个负载均衡 / APP /平衡器/ ,然后将请求发送到 / APP / V1 / / APP / V2 / / APP / V3 / ,等等,那么你可以这样做:

  ProxyPassReverse / APP /平衡器的http://本地主机:8080 / AppContext

另外,你可以将它指向之一,也是最好的希望:

  ProxyPassReverse / APP / V1的http://本地主机:8080 / AppContext

Folks,We are trying to setup Apache reverse proxy for the following scenario:

  • Incoming requests take the form http://foo.com/APP/v1/main.html
  • For some servers the URL will reference a difference version, say, http://foo.com/APP/v2/main.html
  • An upstream load balancer (HAProxy) will send the request to the right server which will have an Apache2 reverse proxy fronting a JBoss server.
  • When the request shows up at Apache 2 it will have request path like /APP/v1/main.html
  • We want it to (reverse) proxy out to http://localhost:8080/AppContext/main.html, irrespective of version fragment in URL (v1, v2, etc.).

I have been trying to do this like so:

ProxyPassMatch ^/.*?/APP.*?/(.*)$ http://localhost:8080/AppContext/$1
ProxyPassReverse /APP http://localhost:8080/AppContext

My questions are:

  1. Is my use of ProxyPassMatch correct?
  2. My ProxyPassReverse is "static". How do I make it aware of the potentially variable stuff after /APP?

Thanks for any insights.

-Raj

解决方案

You're close, try changing the regex a little to account for the version fragment:

ProxyPassMatch ^/.*?/APP.*?/v[0-9]+/(.*)$ http://localhost:8080/AppContext/$1

The ProxyPassReverse is mostly to ensure the rewriting on-the-fly of location header fields in the responses given by the proxied app. So when it returns a 301 redirect to, say, http://localhost:8080/AppContext/something, apache knows to change it to /APP/v1/something so information behind the proxy won't get exposed. Because you have a dynamic URL used in the reverse proxy, you have a few choices here. You can either send it to the HAProxy load balancer (not sure where that is for you), or you can just pick one and hope for the best. For example, if you have a load balancer at /APP/balancer/ which then sends requests to /APP/v1/, /APP/v2/, /APP/v3/, etc. Then you can do this:

ProxyPassReverse /APP/balancer http://localhost:8080/AppContext

Otherwise, you can just point it to one and hope for the best:

ProxyPassReverse /APP/v1 http://localhost:8080/AppContext

这篇关于ProxyPassMatch与ProxyPassReverse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 00:03