Ram*_*Vel 5 ruby-on-rails nginx custom-headers x-accel-redirect
我使用X-Accel-Redirectnginx 在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
Run Code Online (Sandbox Code Playgroud)
这是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;
}
Run Code Online (Sandbox Code Playgroud)
这显然不起作用.我无法在我的回复中获得Content-MD5标题.有没有办法从rails传递我的Content-MD5标题?
我知道有很多方法可以在nginx中完成,比如使用perl或lua编译nginx,并且可以轻松地计算MD5.但我不想这样做.
任何帮助深表感谢.
Ale*_*Ten 12
使用 add_header Content-MD5 $upstream_http_content_md5;
由于X-Accel-Redirect导致内部重定向nginx不会发送返回的标头,但它会将它们保存在$upstream_http_...变量中.所以你可以使用它们.
我已经尝试过接受的答案,但它对我不起作用。但这有效:
set $authorization "$upstream_http_authorization";
proxy_set_header Authorization $authorization; # Pass on secret from back end
Run Code Online (Sandbox Code Playgroud)
(从本文复制粘贴https://clubhouse.io/developer-how-to/how-to-use-internal-redirects-in-nginx/)
有趣的是,提取变量很重要。这对我不起作用:
proxy_set_header Authorization "$upstream_http_authorization";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4389 次 |
| 最近记录: |