Skip to content

Instantly share code, notes, and snippets.

@ecpplus
Created November 21, 2010 17:56
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecpplus/708959 to your computer and use it in GitHub Desktop.
Save ecpplus/708959 to your computer and use it in GitHub Desktop.
Nginx X-Accel-Redirect with Rails
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;
}
# Only for Rails3
# config.action_dispatch.x_sendfile_header = 'X-Sendfile'
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
# 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
# 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