job.answiz.com
  • 4
Votes
name
name Punditsdkoslkdosdkoskdo

Apache selectively reverse-proxy request to a new server

I'm moving a web application to a new set of servers in a different data center. As part of a beta period, I want to configure the old server as a reverse proxy for some requests, based on a pattern in the URL.

For example, if someone requests:

http://old.example.com/foo/bar?q=1

... I want to transparently give them the results of

http://new.example.com/foo/bar?q=1

Redirects won't work, as this is used as an API and some clients don't properly follow redirects (fixing the clients isn't an option). Also, this needs to work for both GET and POST requests.

The list of URLs to proxy would be selective, e.g. so that only the "foo/*" requests would be proxied, and the others would just be served by old.example.com until the final cutover.

Is mod_proxy the right way to go? I can't find any examples that appear to:

  1. Allow selective proxying (e.g. /foo/bar is proxied but /baz/ham is not),
  2. Pass along the entire path and querystring, and
  3. Keep the POST body and all HTTP headers in tact.

Any help would be greatly appreciated.

A forward proxy brokerages the request of the client and forwards the request to the destination of the client’s choice contingent on the configuration of the forward proxy.

Most common uses are to

  • Bypass firewall restrictions.
  • Cache static resources and save bandwidth.
  • Control what resources clients can access.
  • 0
Reply Report

With forward proxy caching, Traffic Server handles web requests to origin servers on behalf of the clients requesting the content. Reverse proxy caching (also known as server acceleration) is different because Traffic Server acts as a proxy cache on behalf of the origin servers that store the content. Traffic Server is configured to behave outwardly as origin server which the client is trying to connect to. In a typical scenario the advertised hostname of the origin server resolves to Traffic Server, which serves client requests directly, fetching content from the true origin server when necessary.

  • 0
Reply Report

From what you describe a simple:

 ProxyPass /foo/ http://new.example.com/foo/

should work. All headers and GET/POST queries should just be forwarded fine. You may need a matching ProxyPassReverse depending on your setup and needs. If you need more control on which URLs are proxied you can use:

 ProxyPassMatch [regex] [url]

The official documentation does a pretty good job at explaining things. If you've tried to proxy like this and it doesn't work a new question with more specific details on what you've tried and what the exact issue is may get you better results.

  • 4
Reply Report