Nginx configures the method to download txt pdf doc xls and so on

  • 2020-05-09 19:53:51
  • OfStack

When using Nginx, if you want to make some attachments such as txt,pdf,doc, etc. not open directly in the browser, but pop up the save as dialog box (that is, download).
Then the header configuration of nginx can be as follows:


if ($request_filename ~* ^.*?\.(txt|pdf|doc|xls)$){ 
    add_header Content-Disposition: 'attachment;'; 


If the client requests a file with txt, pdf, doc, xls suffixes, the save as dialog box will appear in the browser.


Related articles: