Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

File download in nginx specifies how to configure the saved file name

Shulou Source: shulou.com Published: 2022-05-31 12:12:59 09月23日 Update

This article mainly explains the "nginx file download designated save file name how to configure", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in-depth, together to study and learn "nginx file download specified save file name how to configure" it!

Usually, after we upload the resource file, in order to avoid file name conflict, the file name will be changed to a meaningless paragraph of characters. This character may be generated by md5 or a string generated in some other way. At this point, when downloading, the default saved file name will be this meaningless file name (figure 1).

In fact, nginx supports renaming when downloading, making the file name more friendly.

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

The copy code is 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

}

The if line is more critical. When configured in this way, when the n parameter is not passed, it will be saved by the original name. There are no empty names.

Because it is specified in the form of header, cdn will save this header information and will behave the same way when the content is distributed.

Thank you for your reading, the above is the "nginx file download specified save file name how to configure" the content, after the study of this article, I believe that you download the nginx file download specified save file name how to configure this problem has a deeper understanding, the specific use of the need for you to practice verification. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: File file name configuration file download content character learning code name meaning time line information key parameter string that is form idea situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB Shulou Technology Microsoft Xiaomi