Gyong Ju - South Korea

Serving media files from a different url with Django and NGINX

Posted: November 21, 2009 at 8:04 am

Media files in Django are served through the web server and they can be served with a different url than the Django content itself. By spreading requests across multiple urls you can speed up your site because the browser will execute requests in parallel. The rule of thumb seems to be a maximum of 2-3 hostnames otherwise the added DNS requests negate the speed up effect.

In settings.py:

MEDIA_URL = 'media.example.com'

In NGINX:

server {
  listen 80;
  server_name media.example.com;
  location {
    root /PATH/TO/MEDIA/FILES;
  }
}

That’s it, very easy. Oh please replace the media.example.com with your own URL of course.

Comments

No one has said anything yet.

Leave a Comment