ProxyPassMatch with ProxyPassReverse

天大地大妈咪最大 提交于 2019-12-03 11:33:09

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/11852238/proxypassmatch-with-proxypassreverse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!