1

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?

2 Answers 2

2

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.

9
  • I followed django's docs: "We recommend using a separate Web server – i.e., one that’s not also running Django – for serving media." docs.djangoproject.com/en/1.2/howto/deployment/modpython/…
    – Clash
    Feb 17, 2013 at 20:30
  • That's for mod_python deployment and a very old version of the docs. Feb 17, 2013 at 20:32
  • docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi The statement is still there.
    – Clash
    Feb 17, 2013 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, 2013 at 20:41
  • @Clash OK, so you use nginx and you're covered. There's no reason to keep Apache in this scenario. Feb 17, 2013 at 20:42
1

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. http://wiki.nginx.org/XSendfile

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .