Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 向nginx X-Accel-Redirect添加自定义HTTP头_Ruby On Rails_Nginx_Custom Headers_X Accel Redirect - Fatal编程技术网

Ruby on rails 向nginx X-Accel-Redirect添加自定义HTTP头

Ruby on rails 向nginx X-Accel-Redirect添加自定义HTTP头,ruby-on-rails,nginx,custom-headers,x-accel-redirect,Ruby On Rails,Nginx,Custom Headers,X Accel Redirect,我使用nginx的X-Accel-Redirect在rails中提供受限下载服务。为了验证客户端应用程序中的下载,我正在尝试将非标准HTTP头Content-MD5中的校验和发送到X-Accel-Redirect请求。但这是行不通的 下面是用于重定向的rails代码段 headers['X-Accel-Redirect'] = '/download_public/uploads/stories/' + params[:story_id] +'/' + params[:story_id] + '.

我使用nginx的
X-Accel-Redirect
在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。但是我不想那样做


非常感谢您的帮助。

使用
添加标题内容-MD5$upstream\u http\u Content\u MD5


由于
X-Accel-Redirect
导致内部重定向,nginx不会发送返回的头,但会将它们保存在变量中。所以你们可以使用它们。

我试过接受答案,但它对我不起作用。但这是可行的:

 set $authorization "$upstream_http_authorization";
 proxy_set_header Authorization $authorization; # Pass on secret from back end
(从本文粘贴的副本)

有趣的是,提取变量很重要。这对我不起作用:

 proxy_set_header Authorization "$upstream_http_authorization";

尝试
add_header Content-MD5$upstream_Content_MD5
@AlexeyTen,我得到了这个错误
nginx:[emerg]未知的“上游内容”变量
Oops,它是
$上游内容
。请看@AlexeyTen,它有效:)请加上这个作为答案,我会接受同样的问题,但与aws s3重定向。请你看一下这个问题好吗。如果我在“内部”位置内进行代理传递,则非常感谢您的帮助,然后是$上游。。变量变为空。如何解决这个问题?@urmurrull ask new question
nginx不会发送返回的标题
-似乎
内容类型
是一个例外,即使没有
添加标题