Proxypassmatch with Proxypassreverse

Proxypassmatch with Proxypassreverse

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

  • Incoming requests take the form
  • For some servers the URL will reference a difference version, say,
  • 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 , irrespective of version fragment in URL (v1, v2, etc.).

I have been trying to do this like so:

ProxyPassMatch ^/.*?/APP.*?/(.*)$ 
ProxyPassReverse /APP 

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 Answer

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

ProxyPassMatch ^/.*?/APP.*?/v[0-9]+/(.*)$ 

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, , 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 

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

ProxyPassReverse /APP/v1 
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.