about Mod_xsendfile
https://tn123.org/mod_xsendfile/
the X-sendfile in the lighttpd
ROR Web site How to use the LIGHTTPD x-sendfile function to improve file download performance
Using the X-sendfile method, the server-side application does not need to read the download file, only need to set response header information is sufficient, in addition to attach a message "x-lighttpd-send-file" information to LIGHTTPD, Tell lighttpd, the file is downloaded.
the x-sendfile in Apache
Enable PHP to provide file downloads faster
Do not go through the PHP layer, directly let webserver directly to send files, using the Apache module Mod_xsendfile, let Apache send this file directly to the user
<?php $file = "/tmp/Chinese name. tar.gz";
$filename = basename ($file);
Header ("Content-type:application/octet-stream");
Handle Chinese filename
$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). '"');
Let xsendfile send file
header ("X-sendfile: $file");
the X-accel-redirect in the Nginx
Nginx configuration Xsendfile Promote file download performance
Sending a static file uses a header attribute called X-sendfile.
Nginx Of course also has this feature, but the implementation of a slightly different, in Nginx called X-accel-redirect.
There are two features to explain:
The URI must be included in the 1.header
2. Local must be declared as internal for internal Redirect and x-accel-redirect responses.
Configuration Example:
Code
location/public/{
Internal
root/project directory;
}
Application interface:
Code
X_accel_redirect "/project directory/public": filename => "iso.img"
In this way, Nginx will send/project directory/public/iso.img files.
Other examples:
Reference
X_accel_redirect ('/path/to/image.jpg ',: Type => ' Image/jpeg ',:d isposition=> ' inline ')
Rails X_accel_redirect Plugins
Http://github.com/goncalossilva/X-Accel-Redirect
The header also supports the following properties:
Code
x-accel-limit-rate:1024
X-accel-buffering:yes|no
X-accel-charset:utf-8