加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 将自定义HTTP标头添加到nginx X-Accel-Redirec

发布时间:2020-12-17 03:56:08 所属栏目:百科 来源:网络整理
导读:我使用带有nginx的X-Accel-Redirect在rails中提供受限制的下载.为了在客户端应用程序中验证我的下载,我试图将非标准HTTP标头Content-MD5中的校验和发送到X-Accel-Redirect请求.但这不起作用. 用于执行重定向的rails片段下方 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] + '.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_http_content_md5;

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读