当前的浏览器能够识别文件格式,如果浏览器本身能够解析就会默认打开,如果不能解析就会下载该文件。

那么使用nginx做资源服务器的时候,如何强制下载文件呢?

      location /back/upload/file/ {
        if ($request_filename ~* ^.*?\.(txt|pdf|doc|xls)$){  
            add_header Content-Disposition "attachment;";
        }
      }    

如上,在location中添加头信息即可(测试成功,配置完毕./nginx -s reload 需要重新加载配置文件):

add_header Content-Disposition "attachment;";

相关文章:

  • 2022-12-23
  • 2021-07-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
  • 2022-02-01
  • 2021-12-01
  • 2022-12-23
  • 2021-07-13
相关资源
相似解决方案