views:

643

answers:

2

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?

+4  A: 

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

epochwolf
Why and how would you use URL with query parameters? To give the file with wrong file name for the user?
iny
Thank you, that's it.
zgoda
The reason for using a url with query parameters is to tell nginx to only force a download when using /download?file={filename} By using a rewrite rule properly you can add the header and still run through the rest of the rules in nginx's config.
epochwolf
It's possible to ommit the "file=" part of the url and use "/download?{filename}" instead. The format is arbitrary the goal is to somehow let nginx know you need a different header than normal.
epochwolf
A: 

NginxHttpHeadersModule corrected link