APACHE,NGINX,LIGHTTPD use X-sendfile function to promote file download performance separately

Source: Internet
Author: User
Tags sendfile

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.