NGINX下载速度慢,以send_file开头

ips*_*tic 10 ruby-on-rails nginx

我有一个下载链接转到控制器中的方法,该控制器使用send_file,以便我可以重命名该文件(它是一个带有uuid作为文件名的MP3).点击链接后,我在NGINX日志和Rails日志中看到了请求,但下载前需要90秒.我已尝试使用proxy_buffers和client _*_ buffers进行各种设置,但没有任何影响.我有一个HTML5音频播放器,它使用文件的真实URL,它立即流媒体文件,没有延迟.

我的NGINX配置:

upstream app {
  server unix:/home/archives/app/tmp/unicorn.sock fail_timeout=0;
}

server {
  listen      80 default deferred;
  server_name archives.example.com;
  root        /home/archives/app/public/;

  client_max_body_size 200M;
  client_body_buffer_size 100M;
  proxy_buffers 2 100M;
  proxy_buffer_size 100M;
  proxy_busy_buffers_size 100M;

  try_files /maintenance.html $uri/index.html $uri.html $uri @production;

  location @production {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Sendfile-Type X-Accel-Redirect;
    proxy_set_header X-Accel-Mapping /home/archives/app/public/uploads/audio/=/uploads/audio/;
    proxy_redirect off;
    proxy_pass http://app;
  }

  location ~ "^/assets/*" {
    gzip_static on;
    expires     max;
    add_header  Cache-Control public;
  }

  location ~ (?:/\..*|~)$ {
    access_log off;
    log_not_found off;
    deny all;
  }

  error_page 500 502 503 504 /500.html;
  location = /500.html {
    root /home/archives/app/public;
  }
}
Run Code Online (Sandbox Code Playgroud)

Rails控制器:

def download
  send_file @audio.path, type: @audio_content_type, filename: "#{@audio.title} - #{@audio.speaker.name}"
end
Run Code Online (Sandbox Code Playgroud)

ips*_*tic 0

经过测试,我发现是turbolinks导致了这个问题。它在后台执行 XHR 请求,首先下载文件,然后允许浏览器实际下载文件。将 'data-no-turbolink'='true' 添加到我的链接后,立即下载文件。