2

経由でファイルを提供するように Rails アプリをセットアップしました。アプリをビジー状態にしてファイルを提供し続けたくないので、ヘッダーsend_fileを付けて Nginx に渡します。X-Accel-Redirectそのためconfig.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'に、production.rbファイルに設定し、nginx.conf を次のように設定します。

# In order to get the site running
# symlink this file to /etc/nginx/sites-enabled/production

upstream unicorn-production {
  server unix:/tmp/unicorn.sock fail_timeout=0;
}

server {
  listen 3000;
  server_name production.localhost;
  root /home/deployer/apps/production/current/public;
  access_log /var/log/nginx/production_access.log;
  rewrite_log on;

  try_files $uri/index.html $uri @unicorn;

  location ~ ^/downloads/(.*)$ {
    internal;
    alias /home/deployer/downloads/$1;
  }

  location @unicorn {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_redirect off;
    proxy_pass http://unicorn-production;

    proxy_set_header  X-Sendfile-Type   X-Accel-Redirect;
    proxy_set_header  X-Accel-Mapping   /downloads/=/home/deployer/downloads/;

    proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_read_timeout 90;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}

私のコントローラーアクションでは、次のようなことを行います: send_file "/home/deployer/downloads/testfile.foo"

.

これは理論的にはすべて機能するはずですが、mysite.com/mycontroller/downloadChromeにアクセスすると教えてくれますDuplicate headers received from server: Error 349 (net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION): Multiple Content-Disposition headers received. This is disallowed to protect against HTTP response splitting attacks.

どんな助けでも大歓迎です。

4

1 に答える 1

3

このエラーは、send_data を使用するときに、コンテンツの処理ファイル名を引用符で囲むことで修正できます。

から:

send_data data, :type => type,
          :disposition=>"attachment; filename=#{filename}"

に:

send_data data, :type => type,
          :disposition=>"attachment; filename='#{filename}'"

send_file メソッドを使用する場合も同じことが当てはまると思います

参照: https://github.com/prior/prawnto/pull/16

于 2012-04-20T10:33:48.627 に答える