我似乎无法设置从我的Rails应用程序下载的文件的Content-Length。以下是我下载内容时获得的一组典型标题:
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Fri, 29 Jul 2016 07:11:51 GMT
Content-Type: application/zip
Transfer-Encoding: chunked
Connection: keep-alive
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Content-Disposition: attachment; filename="no2.zip"
Content-Transfer-Encoding: binary
Cache-Control: no-store, must-revalidate, private, max-age=0
X-MiniProfiler-Ids: ["blablabla"]
Vary: Accept-Encoding
Content-Encoding: gzip
X-Request-Id: fec224f9-d00c-410b-9ba6-1cd402e51b9f
X-Runtime: 9.224241
Strict-Transport-Security: max-age=31536000
Strict-Transport-Security: max-age=15768000
我注意到Transfer-Encoding也设置为chunked。我正在使用X-Accel-Redirect,我认为必定存在一些问题。
以下是我的nginx设置:
location /stuff/ {
internal;
root /home/rails/blablabla;
}
location @app {
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Accel-Mapping "/home/rails/blablabla/stuff/=/stuff/";
proxy_redirect off;
proxy_pass http://app_server;
}
控制器:
def download
file = @post.zip_location
send_file file
end
我试过了:
response.headers['Content-Length'] = file.size.to_s
response.headers['X-Accel-Buffering'] = 'no'
proxy_set_header X-Accel-Buffering no;
proxy_buffering off;
什么都行不通......我错过了什么?谢谢!