This Rails plugin allows users to take advantage of nginx's X-Accel-Redirect header, similar to X-Send-File.
This plugin was inspired in the x_send_file plugin, which was created before the option :x_sendfile dropped in Rails send_file method (supported since version 2.1).
You should install it as a plugin, running this command on your projects root directory:
$ script/plugin install git://github.com/goncalossilva/XAccelRedirect.git
If everything goes correctly, your application is now ready to use the nginx's X-Accel-Redirect transparently.
X-Accel-Redirect has an equivalent method to Rails send_file, called x_accel_redirect. Using is as easy as:
x_accel_redirect "/path/to/file", :filename => "filename"
All send_file options are available using this method. Now you can even let your old :x_sendfile option since the plugin will discard it.
Overriding Rails default send_file
You can override Rails default method called send_file with x_accel_redirect.
Just add the following line to your environment.rb:
And it's done. Now everytime you call send_file you'll be using x_accel_redirect instead.
You can still access the normal send_file even after specifying the on environment.rb, using the send_file_without_x_accel_redirect method.
For further references, please refer to wiki.nginx.org/NginxXSendfile