Django, Apache, and X-SendFile in Debian
December 31, 2009 Leave a comment
The idea for this post is to allow downloading files only to restricted users. The only constraint for now is that users are logged in. As I add more code to the Django app, I plan to include the ability to specify which users should have access to which files.
This post assumes that you have a working Apache server with VirtualHost file setup for a Django project. I also assume that you would want to access files using a URL scheme such as http://example.com/download/filename.ext where filename.ext represents the file you want to download.
To install X-SendFile in Apache2, run the following:
sudo aptitude install libapache2-mod-xsendfile
And to make sure you enable it, run the following
sudo a2enmod xsendfile
Add the following two lines in your VirtualHost file, like so:
Hat tips: Djangocon X-Sendfile Lightning Talk; Fast File Transfer with X-send file; How to make a private download area with django?; Having Django serve downloadable files; Fast private file transfers for Drupal;