我使用X-Accel-Redirect和nginx在rails中提供有限的下载。为了验证我在客户端应用程序中的下载,我尝试将非标准header 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;
}这显然不起作用。我无法在我的回复中获得内容-md5标题。有什么办法从rails传递我的内容-MD5头吗?
我知道有一些方法可以完全在nginx中实现,比如用perl或lua编译nginx,并轻松地动态计算MD5。但我不想那样做。
任何帮助都是非常感谢的。
发布于 2014-07-01 11:37:49
使用add_header Content-MD5 $upstream_http_content_md5;
因为X-Accel-Redirect会导致内部重定向,所以nginx不会发送返回的头文件,但是它会将它们保存在$upstream_http_...变量中。这样你就可以用它们了。
发布于 2021-06-07 11:38:09
我试过接受答案,但这对我不起作用。但这样做是可行的:
set $authorization "$upstream_http_authorization";
proxy_set_header Authorization $authorization; # Pass on secret from back end(复制粘贴自本文https://clubhouse.io/developer-how-to/how-to-use-internal-redirects-in-nginx/)
有趣的是,提取变量很重要。这对我不起作用:
proxy_set_header Authorization "$upstream_http_authorization";https://stackoverflow.com/questions/24507157
复制相似问题