このメッセージは、nginx.conf で設定が欠落しているため、Rack::Sendfile
無効になっていることを意味します...X-Accel-Redirect
Nginx + Passenger 3 + Rails 3.1を使用しています。
このページから情報を収集して、私はそれを理解しました:
http://wiki.nginx.org/X-accel
http://greenlegos.wordpress.com/2011/09/12/sending-files-with-nginx-x-accel-redirect
http://code.google.com/p/substruct/source/browse/trunk/gems/rack-1.1.0/lib/rack/sendfile.rb?r=355
x-sendfile を使用して Rails 2.3 経由で Nginx を介して大きなファイルを提供する
次の/download/1
ように、独自のディレクトリ構造を持つストレージ ファイルにリクエストをマップするコントローラーがあります。nginx 直接。storage/00/00/1
storage/01/0f/15
send_file
X-Accel-Redirect
コード内で私はこれを持っています:
send_file(
'/var/www/shared/storage/00/00/01',
:disposition => :inline,
:filename => @file.name # an absolute path to the file which you want to send
)
この例の目的でファイル名を置き換えました
次に、これらの行を my に追加する必要がありましたnginx.conf
:
server {
# ...
passenger_set_cgi_param HTTP_X_ACCEL_MAPPING /var/www/shared/storage/=/storage/;
passenger_pass_header X-Accel-Redirect;
location /storage {
root /var/www/shared;
internal;
}
# ...
}
パス/storage
は外の世界からは見えず、内部のみです。
Rack::Sendfile
ヘッダーを取得し、そこからパスを抽出しX-Accel-Mapping
て に置き換えます。次に、変更されたヘッダーを吐き出します。/var/www/shared/storage
/storage...
X-Accel-Redirect: /storage/00/00/01
これはnginxによって処理されます。
ファイルが以前よりも 100 倍高速にダウンロードされ、ログにエラーが表示されないため、これが正しく機能していることがわかります。
お役に立てれば。