我目前有2个图像位置,它们可能是格式(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浏览器中渲染?
这是我的conf文件: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:
location ~* /orig/(.+\.jpg)${
add_header Content-disposition "attachment; filename=$1";
}