Created
November 21, 2010 17:56
-
-
Save ecpplus/708959 to your computer and use it in GitHub Desktop.
Nginx X-Accel-Redirect with Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location / { | |
client_max_body_size 200m; | |
proxy_read_timeout 60; | |
proxy_connect_timeout 60; | |
proxy_pass http://railsapp; | |
} | |
location /bigfiles { | |
# -> /path/to/railsroot/bigfiles | |
root /path/to/railsroot/; | |
internal; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Only for Rails3 | |
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' | |
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails2 | |
def download | |
path = "/bigfiles/long_movie.mp4" | |
response.headers['X-Accel-Redirect'] = path | |
response.headers['Content-Type'] = "application/force-download" | |
response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(path)}\"" | |
response.headers['Content-length'] = File.size(RAILS_ROOT + path) | |
render :nothing => true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails3 | |
def download | |
path = "/bigfiles/long_movie.mp4" | |
send_file path, | |
:type => "application/force-download", | |
:disposition => "attachment; filename=\"#{File.basename(path)}\"" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment