我正在使用X-Accel-Redirect
nginx 在 Rails 中提供受限下载。为了验证我在客户端应用程序中的下载,我尝试将非标准 HTTP 标头中的校验和发送Content-MD5
到X-Accel-Redirect
请求。但这不起作用。
在用于进行重定向的 rails 片段下方
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。但我不想那样做。
任何帮助深表感谢。