Nginx: File download Specifies the configuration to save the file name

Source: Internet
Author: User

Usually after we upload the resource file, in order to avoid the file name conflict, the file name will be changed to a meaningless paragraph of characters. This character, which may be generated by MD5, or a string produced in other ways. At this time, when downloading, the default file name saved is this paragraph of meaningless filename (Figure 1).

In fact, Nginx is supported to rename the download, make the file name more friendly.

Nginx is also easy to configure: Just add the following lines:

Copy the code code as follows:

Location ~*. *\. (doc|txt|jar|zip|apk) (\?. *)?$
{
if ($request _uri ~* ^.*\/(. *) \. ( doc|txt|jar|zip|apk) (\?n= ([^&]+)) $) {
Add_header content-disposition "attachment;filename= $arg _n.$2";
}
Log_not_found off;
Expires 30d;
Break
}

If that line is more critical, so configuration, guaranteed not to pass n parameters, the original name is saved. No empty names appear.

Because it is specified in the header form, the CDN stores this header information, and the content is distributed in the same way.

Nginx: File download Specifies the configuration to save the file name

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.