根据URL区分nginx行为 [英] Differentiate nginx behaviour depending on URL

查看:109
本文介绍了根据URL区分nginx行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Django应用程序,我使用nginx来提供静态内容。不幸的是,所有注册的MIME类型都显示在客户端浏览器中,同时我希望能够下载相同的内容以及常规的行为。说,我有 /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。



Http标题模块文档


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆