我正在通过X-Accel-Redirect通过nginx在rails中发送一些受保护的文件。我已经成功地运行了这个设置在过去的一年(使用rails 3),一切都很好。
我的nginx.conf是
proxy_set_header X-Accel-Mapping /var/www/app/current/public/restricted=/download_restricted/;
passenger_set_cgi_param HTTP_X_ACCEL_MAPPING /var/www/app/current/restricted=/download_restricted/;
passenger_pass_header X-Accel-Redirect;
location /download_restricted {
internal;
proxy_cache editor;
expires max;
#add_header Cache-Control public;
add_header Cache-Control "public, max-age=315360000";
alias /var/www/app/current/public/restricted;
}我的rails代码是
headers['X-Accel-Redirect'] = '/download_restricted/uploads/assets/'+ params[:asset_id] + '/res/' + params[:res] + '.' + params[:format]
headers['X-Accel-Expires'] = 'max'
headers['Content-type'] = MIME::Types.type_for(params[:format])
headers['disposition'] = 'inline'
request.session_options[:skip] = true
render :nothing => true 在rails 3项目中,这个设置仍然运行良好。但是rails 4& nginx,内容类型总是以text/html的形式出现。
我从路径提供音频/视频/图像文件。由于内容类型出错,浏览器没有正确地呈现资产。
对于这些请求,nginx中有set/overwrite the content type的方式吗?
发布于 2014-01-16 12:41:23
经过一些实验之后,我发现我必须将content_type传递给render :nothing来使x-accel重定向来识别内容类型,而且它并不关心headers['Content-type']。
现在这段代码运行良好
render :nothing => true, :content_type => MIME::Types.type_for(params[:format]).first.content_typehttps://stackoverflow.com/questions/21159446
复制相似问题