根据URL区分nginx行为 [英] Differentiate nginx behaviour depending on URL
问题描述
/media/images/image01.jpg
下的JPEG文件,我希望nginx以通常的方式提供此文件,标准的 image / jpeg
标题,但另外我希望与 content-disposition:附件
(有效地)一起提供相同的图像被访问时,例如 /downloads/images/image01.jpg
。任何人都可以提出一个解决方案?确保你已经编译了http_headers_module(应该是默认情况下,在核心中)
使用add_header content-disposition attachment;
我建议使用一个网址/download?file=/downloads/images/image01.jpg结合重写规则,以避免一些烦人的bug。
I have a Django application and I use nginx to serve static content. Unfortunately, all registered MIME types get displayed in client browser, while I would like to give an ability to download the same content, along with usual behaviour. Say, I have JPEG file under /media/images/image01.jpg
and I want that nginx serves this file in usual way, with standard image/jpeg
header, but additionally I want the same image to be served by nginx with content-disposition: attachment
(effectively forcing content download) when accessed as, say, /downloads/images/image01.jpg
. Anybody can suggest a solution?
Make sure you have the http_headers_module compiled in. (should be by default, if it isn't in the core)
Use "add_header content-disposition attachment;"
I recommend using a url like "/download?file=/downloads/images/image01.jpg" combined with a rewrite rule to avoid some annoying bug later.
Http Headers Module Documention
这篇关于根据URL区分nginx行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!