FAQ

Page Discussion Edit History

ChsXSendfile

鍩轰簬搴旂敤绋嬪簭鐨刪eader鏉ュ彂閫侀潤鎬佹枃浠剁殑鐗规�у彨鍋� X-Sendfile.

Lighttpd 鏈夎鐗规��,apache涔熸湁涓ā鍧� 鍙� mod_xsendfile .

Nginx涔熸湁璇ュ姛鑳�,浣嗗疄鐜板緱绋嶅井鏈変簺涓嶅悓.Ngnix璇ュ姛鑳藉彨鍋�X-Accel-Redirect.

涓昏鏈変袱涓笉鍚屼箣澶�:

  1. header 蹇呴』鍖呭惈 URI
  2. location 蹇呴』 琚畾涔変负 internal; 浠ラ樆姝㈠鎴风鐩存帴璁块棶璇� URI

Nginx 閰嶇疆鏍蜂緥:

location /protected/ {
  internal;
  root   /some/path;
}

濡傛灉搴旂敤绋嬪簭杩欎箞鍋氫簡 (浼唬鐮�):

  add_header("X-Accel-Redirect: /protected/iso.img");

...鐒跺悗nginx灏嗗彂閫佹枃浠� /some/path/protected/iso.img (娉ㄦ剰:root璺緞鍜屽唴閮ㄨ烦杞矾寰勬嫾鎺ュ湪涓�璧蜂簡) 缁欏鎴风.

濡傛灉浣犳兂鍙戦�佹枃浠� /some/path/iso.img ,閭d箞閰嶇疆鏂囦欢搴旇杩欎箞鍐�:

location /protected/ {
  internal;
  alias   /some/path/; # 鐣欐剰鏈熬鐨�/
}

Nginx灏嗕笉鏀瑰彉浠ヤ笅鐨刪eaders淇℃伅:

Content-Type
Content-Disposition
Accept-Ranges
Set-Cookie
Cache-Control
Expires

濡傛灉鏈缃繖浜沨eader涔嬩竴,瀹冧滑灏嗙敱閲嶅畾鍚戠殑鍝嶅簲璁剧疆.

搴旂敤绋嬪簭鍦ㄥ鐞嗕腑涔熷彲浠ヨ缃湁闄愮殑鎺у埗,鍦� X-Accel-Redirect 涔嬪墠 鍙戦�佸涓嬬殑header.

X-Accel-Limit-Rate: 1024
X-Accel-Buffering: yes|no
X-Accel-Charset: utf-8


Links to this issue

Using X-Accel-Redirect Header With Nginx to Implement Controlled Downloads (with rails and php examples) from Alexey Kovyrin