Apache proxypass in VirtualHost – shouldn’t it override main

apache-2.2

This is a trivialised example highlighting my situation:

ProxyPass /google/ http://www.google.com/
ProxyPassReverse /google/ http://www.google.com/

<VirtualHost 127.0.0.1:82>
   ProxyPass /google/ http://www.yahoo.com/
   ProxyPassReverse /google/ http://www.yahoo.com/
</VirtualHost>

In this case a request "http://127.0.0.1:82/google/" will try to go to http://www.google.com

I have also found that a ProxyPass defined in main will take precedence over actual directories available in a vhost – eg if in above instead of the VirtualHost having ProxyPass rules its DocumentRoot contained a directory named "google" the Proxy would still be in effect.

Per the apache docs, I had been led to believe any "main" definition would be overridden by a VirtualHost able to satisfy the request.

Best Answer

Unfortunately, You are right. I don't know if this would be right, but you may remedy it by including the default proxy options to [VirtualHost default] section (http://httpd.apache.org/docs/2.0/vhosts/examples.html#default) like this:

<VirtualHost _default_:80>
        ServerName noneset
        DocumentRoot /dev/null
        ProxyPass /google/ http://www.google.com/
        ProxyPassReverse /google/ http://www.google.com/
<VirtualHost>

<VirtualHost *:80>
        ServerName myhost
        DocumentRoot /var/www
        ProxyPass /google/ http://www.yahoo.com/
        ProxyPassReverse /google/ http://www.yahoo.com/

</VirtualHost>

<Proxy *>
                Order deny,allow
                Allow from all
</Proxy>