Skip to content
This repository has been archived by the owner on Dec 29, 2021. It is now read-only.

Latest commit

 

History

History
43 lines (20 loc) · 1.51 KB

README.rdoc

File metadata and controls

43 lines (20 loc) · 1.51 KB

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