6

I'm a little confused as to how to proceed. I'm setting up Django to run on a Mediatemple DV server. I'm trying to figure out the appropriate setup for serving image/video/etc content.

I don't quite understand what this means on http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/

We recommend using a separate Web server -- i.e., one that's not also running Django -- for serving media. Here are some good choices:

lighttpd, Nginx, TUX, A stripped-down version of Apache, Cherokee

Does this mean I should serve Django on one Apache instance (via mod_wsgi) and then serve its content on another instance of Apache or one of the alternatives above? I can do this on the same dedicated virtual server, right? If so, any advice on how I should do that?

Thanks!

Community
  • 1
  • 1
pcpc33
  • 61
  • 2

3 Answers3

7

For the majority of people there is no need for a separate media server. There has been growing criticism over the Django documentation being too liberal in pushing people in that direction when there is no need.

So, don't bother initially and if using mod_wsgi use the the Apache web server for static media as well. It is recommended though that you ensure your run your WSGI application in daemon mode of mod_wsgi as that way the processes serving up static files will be slim and not incur overhead of the actual dynamic web application.

If overly worried about memory usage, also have a read of:

http://blog.dscpl.com.au/2009/11/save-on-memory-with-modwsgi-30.html

See how that all goes and only when Apache itself looks not to be enough, then look to using another server to handle media, the preferred arrangement being to use nginx to handle static media, with nginx also acting as proxy through to Apache/mod_wsgi. Using nginx in front actually allows Apache/mod_wsgi to perform better, which using nginx on a separate domain will not.

Vinay Sajip
  • 95,872
  • 14
  • 179
  • 191
Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
2

Basically what it is saying is that you should use apache using mod_wsgi to serve your django application, and use a more lightweight web server like nginx to serve up your static content.

For example.

www.yourapp.com -> apache -> mod_wsgi -> your django app

static.yourapp.com -> nginx

By separating your concerns you can configure your apache instance to be your dump truck handing the heavy processing, and your nginx server to be light and fast like a racecar serving lots of little static files.

If you configure nginx so that it handles all web traffic, you can reverse proxy all django requests to apache behind it, and intercept all of the static files and serve those strait from nginx.

see these links for more information.

http://codespatter.com/2009/04/23/how-to-speed-up-your-django-sites/

django : Serving static files through nginx

https://serverfault.com/questions/122809/django-serving-static-files-through-nginx

https://serverfault.com/questions/199038/serving-static-files-fails-nginx

Community
  • 1
  • 1
Ken Cochrane
  • 75,357
  • 9
  • 52
  • 60
-1

Ken is right in his assessment and in recommending serving everything behind a NGINX proxy. That is the way to go.

You can have your application and media servers on the same server or different ones. For most applications, it won't matter and it is fine to serve both media and apps from the same machine.

If you are looking at lots of users and heavy traffic, breaking the media server out into it's own machine will prevent the two from crashing each other and allow you a bit more flexibility.

Check out Gunicorn if you haven't already as it is a lightning fast, easy to deploy application server and is the new hotness.

Dana Woodman
  • 4,148
  • 1
  • 38
  • 35