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

I serve all static files (/static/ and /media/) via nginx and all other requests are routed to apache using mod_wsgi to use django. nginx acts as proxy through to Apache/mod_wsgi. As far as I know this is the recommended way, that one static files should be served separately.

Now I have the following situation, a user wants to download a file, but I need first to check if the user is allowed to download this file (which is not on /static/ neither /media/, obviously, else it would be public). This means the request has to go first to django. I suppose the recommended practice here is to -not- let apache serve the file, so if the user is authorized to download the file, is there anyway I can tell apache to use nginx to serve this file?

share|improve this question

First of all, you don't need to use both nginx and apache. One of them is enough and can do both static and dynamic content properly. I'd advise nginx because of part two of your question.

If you want django-based access control on your files, use X-SendFile to tell tell the webserver which file to serve.

share|improve this answer
I followed django's docs: "We recommend using a separate Web server – i.e., one that’s not also running Django – for serving media."… – Clash Feb 17 '13 at 20:30
That's for mod_python deployment and a very old version of the docs. – Dennis Kaarsemaker Feb 17 '13 at 20:32 The statement is still there. – Clash Feb 17 '13 at 20:35
@Michael, "Django’s primary deployment platform is WSGI, the Python standard for web servers and applications.", so I'm using apache+modwsgi. I also posted a link about mod_wsgi, the statement about having a separate web server is the same. – Clash Feb 17 '13 at 20:41
@Clash OK, so you use nginx and you're covered. There's no reason to keep Apache in this scenario. – Michael Hampton Feb 17 '13 at 20:42

Because nginx is the reverse proxy, it actually receives the response before sending it to the user. I set manually the X-Accel-Redirect header from django and it worked flawlessly just like I wanted.

share|improve this answer

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.