Nginx serving static files; apache django; secure file from apache to nginx

apache-2.2djangonginx

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?

Best Answer

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.