nginx:使用 Content-Disposition 强制整个目录的文件下载

要使用 nginx 通过 Content-Disposition 头强制下载目录中的所有文件,使用此代码片段:

force_download.conf
# 强制 /scripts 中的文件下载而不是显示!
location ~ ^/scripts/(?P<request_basename>[^/]+)$ {
    add_header Content-Disposition "attachment; filename=$request_basename";
}

注意这可能会在不使用正确文件系统的一些移动 iOS 设备上引起问题。

原始来源:coderwall.com(但经过了大量修改)


Check out similar posts by category: Nginx