How to force file download in the browser, nginx server

前端 未结 4 1378
误落风尘
误落风尘 2021-01-04 05:38

I currently have 2 image locations and they may the formats (jpg,jpeg,png,gif)

i.domain.com/simage.jpg thumbnail
i.domain.com/image.jpg high quality
i.domain         


        
4条回答
  •  生来不讨喜
    2021-01-04 06:16

    Below config works for me.

    server {
        ...
        # Django media
        location /media  {
            alias /var/www/media;  
            types { application/octet-stream .pdf; }
            default_type application/octet-stream;
        }
        ...
    }
    

    But the pdf file needs to ends with lowercase pdf for download to work. I still don't know the syntax to add both .pdf and .PDF to above config file. Any suggestion? The answer is based on info from http://210mike.com/force-file-download-nginx-apache/

提交回复
热议问题