Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Force download for certain URLs with ?force_download
set $forceDownload "";
set $filename "";
if ($request_filename ~ /([^/]+)$) {
set $filename $1;
}
if ($request_uri ~ [\?&]force_download(=(?<filename>[^&$]+)|&|$)) {
set $forceDownload "attachment; filename=\"$filename\"";
}
# block hidden files
if ($filename ~ ^\.) {
set $forceDownload "";
}
if ($sent_http_content_disposition) {
set $forceDownload $sent_http_content_disposition;
}
more_set_headers -s 200 "Content-Disposition: $forceDownload";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.