bjghzly 发表于 2016-12-23 10:35:21

nginx x-sendfile下载

  // 利用nginx直接下载文件,提高效率
  public function download_apk_efficient($internal_file_path,$file_name){
  // And redirect user to internal location
  header("Content-Type: application/vnd.android.package-archive");
  header("Content-Disposition: attachment; filename=".$file_name);
  header("X-Accel-Redirect: " . $internal_file_path);
  }
  调用的:
  Module::factory("Download")->download_apk_efficient("/promoter_files/". $relative_file_path, $out_name); //promoter_files是在nginx的innernal中配置的路径,例如我下载/server/hosting/mobilechannel/promoter_download2/12/1.file,这里实际调用的是download_apk_efficient("/promoter_files/12/1.file" ,$out_name)
  在nginx里配置:
  location /promoter_files/ {   #/promoter_files/是我取的名字,表示alias字段代表的路径
  internal;
  alias   /server/hosting/mobilechannel/promoter_download2/;   #这里是文件的实际路径
  }
页: [1]
查看完整版本: nginx x-sendfile下载