Guest User

Untitled

a guest
Feb 19th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. # How to force a file download with Nginx?
  2.  
  3. In short:
  4.  
  5. ```nginx
  6. add_header Content-Disposition 'attachment; filename="foo.txt"';
  7. ```
  8. We’re just adding a `Content-Disposition` header in the response.
  9. You can specify the file name, here we’re using `foo.txt`.
  10.  
  11. From there you can config the file name to be dynamic, using Nginx’s variables.
  12. For instance using `$arg_filename`:
  13.  
  14. ```nginx
  15. add_header Content-Disposition 'attachment; filename="$arg_filename"';
  16. ```
  17.  
  18. You can now send a `GET` request with `?filename=hey.txt`, and the filename will be set to `hey.txt` as the download starts.
Add Comment
Please, Sign In to add comment