如何在浏览器,nginx服务器中强制文件下载 [英] How to force file download in the browser, nginx server
本文介绍了如何在浏览器,nginx服务器中强制文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有2个图像位置,它们的格式可能是(jpg,jpeg,png,gif)
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.com/o/image.jpg full resolution
有人知道我如何强制/o/中的图像文件下载而不是在Web浏览器中呈现吗?
Does anyone know how I can force image files in /o/ to download rather than render in the web browser?
这是我的conf文件: http://pastebin.com/dP8kZMzx
Here's my conf file: http://pastebin.com/dP8kZMzx
#setup subdomain i.domain.com
server {
server_name i.domain.com;
access_log /var/log/nginx/i..com.access.log;
error_log /var/log/nginx/i.domain.com.error.log;
root /var/www/domain.com/test1/images;
index index.php index.html index.htm;
#error_page 403 = /notfound.jpg;
#error_page 500 = /notfound.jpg;
location / {
#change this to a 404 img file .jpg
try_files $uri $uri/ /notfound.jpg;
rewrite "/s([A-Za-z0-9.]+)?" /small/$1 break;
rewrite "/o/([A-Za-z0-9.]+)?" /orig/$1 break;
rewrite "/([A-Za-z0-9.]+)?" /medium/$1 break;
}
}
推荐答案
您只需要返回HTTP标头Content-disposition
:
You just need to return HTTP header Content-disposition
:
location ~* /orig/(.+\.jpg)$ {
add_header Content-disposition "attachment; filename=$1";
}
这篇关于如何在浏览器,nginx服务器中强制文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文