0

I'm having trouble serving static files through my web server running mod_wsgi and dJango. Our server provider is Heroku.

Because the files are static, and should not be evaluated, I've heard that they should be served directly instead of going through mod_wsgi instead and dJango should not touch them?

I feel like this should be a simple thing, but I'm struggling with it. I'd really appreciate it if anyone could point me in the right directing as to how I should be attempting to store and serve static files?

Chris Dutrow
  • 48,402
  • 65
  • 188
  • 258
  • 1
    I'm very interested in this question. But, I fear that solution will be to store static files in amazon S3 (or some other provider) with other static storage. Remember that django provides `STATIC_URL` parameter. Are you moving http://www.sharpdetail.com/ from php to django? ;) – dani herrera Jul 18 '12 at 15:38
  • @danihp - I had considered S3, I was thinking there may have been a simpler solution, but perhaps not? This is for web application, not the Sharp Detail website. I figure Heroku might be overkill for that :) Thanks for your help! – Chris Dutrow Jul 18 '12 at 15:45
  • 1
    I use webfaction, and the way static files are handled is to create a `Static-only` application, point it to `www.mydomain.com/static_files`. I also keep `static_files` as my django `STATIC_URL`. Now configure nginx (or any other server process) to serve this `static-only` application. – zaphod Jul 18 '12 at 15:52
  • How are you getting mod_wsgi onto Heroku as neither Apache or mod_wsgi are there by default? I started working on an Apache/mod_wsgi build pack for Heroku, but haven't had a chance to touch it much. – Graham Dumpleton Jul 19 '12 at 02:27

1 Answers1

1

The idea is to use the Web server to handle requests for static files and not pass those through to your Django instance. The reason for that is that Web servers, unlike your Django application, are optimized for delivering static content.

The only thing you really need to do is configure your Web server to handle requests that match the path of your STATIC_URL and MEDIA_URL by setting the document root for those requests to the location where your static and media files are stored by your application.

Filip Dupanović
  • 32,650
  • 13
  • 84
  • 114