In short:
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:
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.