Apache,Nginx,Lighttpd分别使用X-sendfile功能提升文件下载性能
来源:互联网 发布:传奇盛世魂珠暴击数据 编辑:程序博客网 时间:2024/06/06 18:34
关于mod_xsendfile
https://tn123.org/mod_xsendfile/
Lighttpd中的X-sendfile
RoR网站如何利用lighttpd的X-sendfile功能提升文件下载性能
使用X-sendfile方式,服务器端应用程序不需要读取下载文件了,只需要设置response的header信息就足够了,此外还要附加一个信息“X-LIGHTTPD-send-file”信息给lighttpd,告诉lighttpd,文件下载就不管了
Apache中的X-sendfile
让PHP更快的提供文件下载
不经过PHP这层, 直接让Webserver直接把文件发送,使用Apache的module mod_xsendfile, 让Apache直接发送这个文件给用户给用户
- <?php $file = "/tmp/中文名.tar.gz";
- $filename = basename($file);
- header("Content-type: application/octet-stream");
- //处理中文文件名
- $ua = $_SERVER["HTTP_USER_AGENT"];
- $encoded_filename = urlencode($filename);
- $encoded_filename = str_replace("+", "%20", $encoded_filename);
- if (preg_match("/MSIE/", $ua)) {
- header('Content-Disposition: attachment; filename="' . $encoded_filename . '"');
- }
- else if (preg_match("/Firefox/", $ua))
- {
- header("Content-Disposition: attachment; filename*=\"utf8''" . $filename . '"');
- }
- else {
- header('Content-Disposition: attachment; filename="' . $filename . '"');
- }
- header('Content-Disposition: attachment; filename="' . basename($file) . '"');
- //让Xsendfile发送文件
- header("X-Sendfile: $file");
Nginx中的X-Accel-Redirect
nginx配置xsendfile提升文件下载性能
发送静态文件使用的是一个叫做X-sendfile的header特性.
nginx当然也有这个特性,但是实现的略微不同,在nginx中叫做X-Accel-Redirect.
有两个特性需要阐述:
1.header 中必须包括URI
2.本地必须声明为 internal,用于内部redirect和X-Accel-Redirect responses。
配置例子:
代码
location /public/ {
internal;
root /项目目录;
}
应用程序接口:
代码
x_accel_redirect "/项目目录/public", :filename => "iso.img"
这样,nginx将发送/项目目录/public/iso.img 文件。
其他例子:
引用
x_accel_redirect(‘/path/to/image.jpg’, :type => ‘image/jpeg’, :disposition=>’inline’)
rails x_accel_redirect 插件
http://github.com/goncalossilva/X-Accel-Redirect
header还支持如下属性:
代码
X-Accel-Limit-Rate: 1024
X-Accel-Buffering: yes|no
X-Accel-Charset: utf-8
- Apache,Nginx,Lighttpd分别使用X-sendfile功能提升文件下载性能
- Apache,Nginx,Lighttpd分别使用X-sendfile功能提升文件下载性能
- 转:RoR网站如何利用lighttpd的X-sendfile功能提升文件下载性能
- RoR网站如何利用lighttpd的X-sendfile功能提升文件下载性能
- 使用 Nginx 的 X-Sendfile 机制提升 PHP 文件下载性能
- 使用Nginx的X-Sendfile机制提升PHP文件下载性能
- 使用 sendfile() 提升网络文件发送性能
- 使用 sendfile() 提升网络文件发送性能
- 使用sendfile提升性能
- php nginx用x-sendfile控制文件下载权限
- PHP apache X-sendfile扩展实现文件下载
- sendfile()对Nginx性能的提升
- sendfile()对Nginx性能的提升
- sendfile()对Nginx性能的提升
- nginx Lighttpd Apache 性能测试
- Apache、nginx 、lighttpd性能比较
- Apache、Nginx 、Lighttpd性能比较
- Apache、Nginx 、Lighttpd性能比较
- 教你如何使用JMock来实现孤立测试
- sql 标量值函数
- Linux系统的休眠与唤醒简介 .
- 电磁继电器工作原理
- 让AlertDialog在按钮被点击后不消失【android搞死你】
- Apache,Nginx,Lighttpd分别使用X-sendfile功能提升文件下载性能
- 领域建模的思想和方法
- Android 平铺图片
- C#音频采集代码
- 使用Firebug的console导致IE提示对象未定义错误
- FORM:在不同窗口中传递参数
- POJ 状态DP+ 01 背包问题
- perl fork 后出现僵尸进程的处理
- openstack block migration 块迁移