1

When using apache to reverse proxy, is it possible to forward http://somesite.com/ and http://somesite.com/foo to different servers? Say one goes to http://internalserver1/ and the other goes to http://internalserver2/foo

I can obviously just drop further down the path (ie http://somesite/bar) but its not desirable.

1
  • Take a look at Nginx as a reverse proxy over Apache, it's relatively new but has already surpassed LightHttp in use and it very fast and lightweight. Aug 6, 2009 at 18:02

2 Answers 2

3

it seems that order of directives in your vhost is important. and yes - you can achieve what you need. i just run test for:

ProxyPass /q http://host.one.com/img/
ProxyPass / http://another.host/

and it worked fine - all requests [ except those directed to /q/something ] ware proxied to another.host. those for /q/whatever - went to host.one.com

4
  • hmm, this didnt work for me, i ended up with the same issue without order - all links went to (in your example) another.host did you include ProxyPassReverse?
    – Devnull
    Jul 22, 2009 at 21:05
  • @ANervousTwitch i'm sorry to hear it but this actually does work for me. no - i do not have ProxyPassReverse, only two lines for proxy: "ProxyPass /q stackoverflow.com" and "ProxyPass / serverfault.com" after that.
    – pQd
    Jul 22, 2009 at 21:19
  • @ANervousTwitch - i'm using apache 2.2.9-10 from debian.
    – pQd
    Jul 22, 2009 at 21:19
  • I agree that this should work.
    – radius
    Jul 22, 2009 at 22:58
2

You should be able to do this using mod_rewrite. It evaluates conditions in order and you can specify the [L] flag to make it stop processing further rules.

RewriteEngine On
RewriteRule /foo/(.*) http://internalserver2/foo/$1 [P,L]
RewriteRule /(.*)     http://internalserver/$1 [P]

Full mod_rewrite documentation is at http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.