[Mongrel] Static files in public

Ian C. Blenke ian at blenke.com
Fri Sep 22 13:18:37 EDT 2006

Kris Leech wrote:
> Thanks for the replies, I have read the apache page in the mongrel docs 
> already, I guess I didnt explain too well, but what I do get is that if 
> Apache and Mongrel are on the same physical machine that you can set 
> Apache's DocumentRoot to the public folder and it would look there for 
> static files first. But if Apache and Mongrel are on different machines 
> Apache does not have access to the files in public...
> I hope that makes my question a bit clearer?

The easiest way is to define an "asset_host":

    config.action_controller.asset_host = "http://assets.example.com"

Look at your "config/environments/production.rb" file, you should see
that line in there.

When rails helpers generate links to static content, the above
asset_host is used in the URLs.
Browsers would then go to your asset server cluster to get that static

The "other" way to address this would be to have a "reverse proxy" tier
in front of your web tier and rails tier that would use something like
mod_rewrite rules to shunt content to the appropriate cluster. If the
static files are more difficult to identify than simply grouping the
content directories (/images/, /javascript/, /stylesheets/), that would
mean adding a new RewriteRule everytime you add some static content,
unless the "reverse proxy" tier has a local reference copy to use to
know where to shunt the request.

On the other hand, if your reverse proxy tier already has an rsynced
copy of the public folder static content, and can serve that static
content directly, it is arguable why you wouldn't simply host the static
content off of your reverse proxy tier directly. This is what many folks
appear to be doing with apache 2.2 and mod_proxy_balancer right now.

- Ian C. Blenke <ian at blenke.com> http://ian.blenke.com/

More information about the Mongrel-users mailing list