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.

Devnull
  • 951
  • 1
  • 7
  • 23
  • Take a look at [Nginx](http://wiki.nginx.org/Main) as a reverse proxy over Apache, it's relatively new but has already surpassed LightHttp in use and it very fast and lightweight. – Robert Swisher Aug 06 '09 at 18:02

2 Answers2

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

pQd
  • 29,981
  • 6
  • 66
  • 109
  • 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 '09 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 http://stackoverflow.com/" and "ProxyPass / http://serverfault.com/" after that. – pQd Jul 22 '09 at 21:19
  • @ANervousTwitch - i'm using apache 2.2.9-10 from debian. – pQd Jul 22 '09 at 21:19
  • I agree that this should work. – radius Jul 22 '09 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

Brandon
  • 1,246
  • 8
  • 5