【发布时间】:2014-08-21 19:55:09
【问题描述】:
我正在使用 X-Accel-Redirect 和 nginx 在 Rails 中提供受限下载。为了验证我在客户端应用程序中的下载,我尝试将非标准 HTTP 标头 Content-MD5 中的校验和发送到 X-Accel-Redirect 请求。但这不起作用。
sn-p 用于重定向的轨道下方
headers['X-Accel-Redirect'] = '/download_public/uploads/stories/' + params[:story_id] +'/' + params[:story_id] + '.zip'
headers['X-Accel-Expires'] = 'max'
checksum = Digest::MD5.file(Rails.root.dirname.to_s+'/public/uploads/stories/' + params[:story_id] +'/' + params[:story_id] + '.zip').hexdigest
headers['Content-MD5'] = checksum
request.session_options[:skip] = true
render :nothing => true, :content_type => MIME::Types.type_for('.zip').first.content_type
这是 nginx 部分
location /download_public {
internal;
proxy_pass_header Content-MD5;
add_header Cache-Control "public, max-age=315360000";
add_header Content-Disposition "inline";
alias /var/www/sss/public;
}
这显然不起作用。我无法在回复中获取 Content-MD5 标头。有什么方法可以从 rails 传递我的 Content-MD5 标头?
我知道有一些方法可以完全在 nginx 中完成,例如使用 perl 或 lua 编译 nginx 并轻松计算 MD5。但我不想那样做。
非常感谢任何帮助。
【问题讨论】:
-
试试
add_header Content-MD5 $upstream_content_md5; -
@AlexeyTen,我收到了这个错误
nginx: [emerg] unknown "upstream_content_md5" variable -
糟糕,我是
$upstream_http_content_md5。见nginx.org/r/$upstream_http_ -
@AlexeyTen,它有效.. :) 请将此添加为答案,我会接受它
标签: ruby-on-rails nginx custom-headers x-accel-redirect