When using mod_proxy to load balance between members of a mongrel or thin cluster it’s important not to pass requests through for static content. A basic virtual site can be configured like this:
<VirtualHost *:80> ServerName myapp.mydomain.com DocumentRoot /opt/myapp/public <Proxy balancer://thinservers> BalancerMember http://127.0.0.1:3000 BalancerMember http://127.0.0.1:3001 BalancerMember http://127.0.0.1:3002 </Proxy> ProxyPreserveHost On ProxyPass /images ! ProxyPass /stylesheets ! ProxyPass /javascripts ! ProxyPass / balancer://thinservers/ ProxyPassReverse / balancer://thinservers/ <Proxy *> Order deny,allow Allow from all </Proxy> ErrorLog /var/log/apache2/error.log LogLevel warn CustomLog /var/log/apache2/access.log combined </VirtualHost>
Hi Piers,
Why do you explicitly list images, stylesheets, javascripts in the ProxyPass directive. They won’t ever get forwarded to Thin since they are real files, as defined in:
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
or am I missing something?
The short answer is that’s what works, without the ProxyPass filters the static resources don’t get served. I think ProxyPass / … proxies everything regardless of whether the URL was rewritten. I had to add the ProxyPass filters when I upgraded to Rails 3: I guess Rails 2 served static content by default and that got turned off with the new version.
Looking at http://www.ruby-forum.com/topic/156523 I realize now it’s the URL rewrite that’s redundant, I’ve removed it from my site configuration and the post above.
With rails 3.1 and asset pipeline use
ProxyPass /assets !
instead of the three
ProxyPass /images !
ProxyPass /stylesheets !
ProxyPass /javascripts !
[…] used Apache with Mongrel, Thin and Passenger, I’ve now moved on to Unicorn. Setting up Apache on Ubuntu to proxy to […]