About mod_xsendfile
Https://tn123.org/mod_xsendfile/
X-sendfile in Lighttpd
How the ROR website uses the X-sendfile function of Lighttpd to improve File Download Performance
In the X-sendfile mode, server applications do not need to read the downloaded files. You only need to set the response header information, in addition, you need to append the "x-Lighttpd-send-file" information to Lighttpd, telling Lighttpd that the file download will not work.
X-sendfile in Apache
Allows PHP to provide faster file downloads
Without passing through the PHP layer, the webserver directly sends the file, and uses the Apache module mod_xsendfile to allow Apache to directly send the file to the user.
<? PHP $ file = "/tmp/Chinese name .tar.gz"; $ filename = basename ($ file); header ("Content-Type: Application/octet-stream "); // process the Chinese file name $ 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 the file header (" X-sendfile: $ file ");
X-accel-redirect in nginx
Configure xsendfile in nginx to improve File Download Performance
The header feature called X-sendfile is used to send static files.
Nginx also has this feature, but the implementation is slightly different. It is called X-accel-redirect in nginx.
There are two features that need to be elaborated:
1. the header must contain the URI
2. The local file 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 the/project directory/public/ISO. IMG file.
Other examples:
Reference
X_accel_redirect ('/path/to/image.jpg',: TYPE => 'image/JPEG ',: Disposition => 'line ')
Rails x_accel_redirect plug-in
Http://github.com/goncalossilva/X-Accel-Redirect
The header also supports the following attributes:
Code
X-accel-limit-rate: 1024
X-accel-buffering: Yes | No
X-accel-charset: UTF-8