Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # How to force a file download with Nginx?
- In short:
- ```nginx
- add_header Content-Disposition 'attachment; filename="foo.txt"';
- ```
- We’re just adding a `Content-Disposition` header in the response.
- You can specify the file name, here we’re using `foo.txt`.
- From there you can config the file name to be dynamic, using Nginx’s variables.
- For instance using `$arg_filename`:
- ```nginx
- add_header Content-Disposition 'attachment; filename="$arg_filename"';
- ```
- 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