README.md in rack-mogilefs-0.2.0 vs README.md in rack-mogilefs-0.3.0

- old
+ new

@@ -2,49 +2,18 @@ If you are using Nginx you'll probably want to serve MogileFS files with the [MogileFS Module](http://www.grid.net.ru/nginx/mogilefs.en.html), but if you need a quick way to serve them out of a Rack app, this should help. -## Caveats ( serving files vs reproxying ) - -Serving files through Ruby is slow. The preferred method is to set an -X-Reproxy-Url header from your app and let the web server serve the file. For -Nginx, you could have a config like this: - - location /reproxy { - internal; - set $reproxy $upstream_http_x_reproxy_url; - proxy_pass $reproxy; - proxy_hide_header Content-Type; - } - -For Apache, there is [mod_reproxy](http://github.com/jamis/mod_reproxy) - -`Rack::MogileFS` will use this method if you pass a strategy option of `:reproxy` - - use Rack::MogileFS, :strategy => :reproxy - -`Rack::MogileFS` will look up the internal urls for the file, and set two -headers to reproxy the request: - - X-Accel-Redirect: /reproxy - X-Reproxy-Url: http://internal.ip/path/to/mogile/file.fid - -You'll have to make sure your web server knows how to handle this request. - ## Getting Started: First install the gem: gem install rack-mogilefs There are a variety of ways to use it: -### Rack middleware - # (config.ru) - use Rack::MogileFS, :path => %r{^/assets/*} - ### Rails 3: # (config/routes.rb) match "/assets/*" => Rack::MogileFS::Endpoint.new @@ -59,10 +28,14 @@ [ 404, { "Content-Type" => "text/html" }, ["Not Found"] ] end end end +### Rack middleware + # (config.ru) + use Rack::MogileFS, :path => %r{^/assets/*} + ## File Lookup `Rack::MogileFS` uses the request path (`PATH_INFO`) for the MogileFS key. The content type of the file is detected by the extension, using the `mime-types` gem. @@ -98,5 +71,37 @@ MogileFS::MogileFS.new( config["connection"].symbolize_keys ) You can override this by passing in a MogileFS client of your own: Rack::MogileFS::Endpoint.new :client => MyMogileFSClient.new + +## Caveats ( serving files vs reproxying ) + +Serving files through Ruby can be slow. `Rack::MogileFS` will read the entire +file into memory before sending it downstream. If you have varnish/squid/a CDN +sitting in front of rails then this isn't so problematic. + +The preferred method is to set an X-Reproxy-Url header from your app and let +the web server serve the file instead of `Rack::MogileFS`. For Nginx, you +could have a config like this: + + location /reproxy { + internal; + set $reproxy $upstream_http_x_reproxy_url; + proxy_pass $reproxy; + proxy_hide_header Content-Type; + } + +For Apache, there is [mod_reproxy](http://github.com/jamis/mod_reproxy) + +`Rack::MogileFS` will use this method if you pass a strategy option of `:reproxy` + + use Rack::MogileFS, :strategy => :reproxy + +`Rack::MogileFS` will look up the internal urls for the file, and set two +headers to reproxy the request: + + X-Accel-Redirect: /reproxy + X-Reproxy-Url: http://internal.ip/path/to/mogile/file.fid + +You'll have to make sure your web server knows how to handle this request. +