2

I have some static files that I would like to serve, and I aware that Django and Python are not suitable for serving static files in a production environment.

My current set up is nginx with python/django behind it wither via nginx_fastcgi or uwsgi workers. Nginx serves up static files like the CSS and the Javascript, and all the dynamic pages are passed on to python to generate.

However there are urls like /user/input/battleships.in. Here battleships.in is a static file located on the filesystem at `$MEDIA_ROOT/users/$request.user.username. Is there a way to have django determine the correct url, and then proxy the request back to nginx to serve the static file?

Varun Madiath
  • 3,152
  • 4
  • 30
  • 46
  • check http://stackoverflow.com/questions/1609273/how-to-make-a-private-download-area-with-django and http://stackoverflow.com/questions/7296642/django-understanding-x-sendfile – okm Apr 03 '12 at 09:26
  • Between those two links I was able to figure out what to do. Would you make an answer simply saying use X-Accel-Redirect so I can mark it as answered? – Varun Madiath Apr 03 '12 at 09:58
  • glad it helps. You could also post and pick up an final solution later if its helps in code, maybe some package named `django-downloadble` =p – okm Apr 03 '12 at 10:20

1 Answers1

5

Try to be not that trival =)

use X-accel module of Nginx. check

Community
  • 1
  • 1
okm
  • 23,575
  • 5
  • 83
  • 90