Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my nginx 0.8.34 setup I'm using the X-Accel-Redirect feature to control file downloads in the application code while not having the application handle the download itself.

After much pain this now basically works except nginx always returns the file with text/html content type.

The default content type is application/octet-stream, specified in the http block.

The server block contains, among other things, the definition of the directory where the files are stored:

location /files {
  default_type  application/octet-stream;
  alias /srv/www/uploads;

So I specified the content type even here but nothing has changed.

I don't want to set the Content-Type by the application because then I would slow me down (I'd first have to determine it). So ideally nginx would return the correct mimetype based on the file extension (I do include mime.types in the http block).

share|improve this question
up vote 6 down vote accepted

If you want to let nginx guess the right mime type, you juste have to make sure no content-type is returned from your backend server.

With django:
    response = HttpResponse()
    response['Content-Type'] = ''
    response['X-Accel-Redirect'] ='/my/file.jpg'
    return response
share|improve this answer
with tornado: tornado.web.RequestHandler.clear(self) self.set_header('X-Accel-Redirect', redirect_location) self.clear_header('Content-Type') as the .clear method sets content-type to text/html – Anthony Jan 16 '15 at 18:17

I personally just set application/octet-stream in the application but you might be able to use fastcgi_ignore_headers to prevent Nginx from using the back-end supplied header.

fastcgi_ignore_headers Content-Type;
share|improve this answer
Thank you for your answer. I want to server different content types so that images render as images and zip files are offered as a download option. So unfortunately this does not quite solve it. – Tomas Kohl Oct 27 '10 at 14:45
Did you try it or are you just assuming it won't work? By ignoring the back-end supplied header it should try to determine it based on the file. – Martin Fjordvald Oct 27 '10 at 16:08
One cannot ignore Content-Type. According to possible values are X-Accel-Redirect, X-Accel-Expires, Expires or Cache-Control – jnns Dec 7 '11 at 17:11
"It is possible to specify headers like" while shitty phrasing does not mean "the possible values are". I have ignored Content-Type before in combination with x-accel-redirect so I don't think it's impossible, though, I'll admit I'm not intimate with the gritty details. – Martin Fjordvald Dec 8 '11 at 15:51
@MartinFjordvald, tried it and nginx refused to start complaining nginx: [warn] invalid value "Content-Type" in /etc/nginx/conf.d/default.conf:27 but fastcgi_ignore_headers "Expires" works – dnozay Feb 27 '14 at 23:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.