ProxyPass and static resources
View blog reactions Written on April 23, 2007 by Chris Heald
When proxying requests out to a load balancer, it’s often useful to avoid proxying some things. In the case of a Rails app, there is no need to proxy requests for images, JS, CSS, etc out to the Mongrel instances - Apache is perfectly capable of handling those itself.
There are several methods of doing this - one is to use RewriteRules to determine which URLs to not rewrite, but this is often more power than we need, and can be rather slow, depending on your implmentation. Fortunately, there’s a better way.
ProxyPass gives you a very easy way to say “don’t proxy this url” - just set your proxy target to “!”.
The following example demonstrates how you’d set up a ProxyPass mechanism to proxy everything except urls containing /images, /stylesheets, etc.
<VirtualHost *:80>
ServerName myserver.com
DocumentRoot /var/www/myapp/public
ProxyPass /images !
ProxyPass /stylesheets !
ProxyPass /javascripts !
ProxyPass / balancer://my_load_balancer/
ProxyPassReverse / balancer://my_load_balancer/
</VirtualHost>
Quick, easy, no mess, no fuss.
Posted in 