Skip to content
A Ruby on Rails plugin for X-Accel-Redirect support (the nginx equivalent of X-Sendfile)
Ruby
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
README.rdoc
Rakefile
init.rb

README.rdoc

XAccelRedirect

This Rails plugin allows users to take advantage of nginx's X-Accel-Redirect header, similar to X-Send-File.

Credits

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).

Install

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.

Usage

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:

XAccelRedirect::Plugin.replace_send_file!

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.

Notes

For further references, please refer to wiki.nginx.org/NginxXSendfile

Something went wrong with that request. Please try again.