Install problems with XSendFile on Ubuntu

I installed the apache dev headers:

sudo apt-get install apache2-prefork-dev

Downloaded and compiled the module as outlined here: http://tn123.ath.cx/mod_xsendfile/

Added the following line to /etc/apache2/mods-available/xsendfile.load:

LoadModule xsendfile_module /usr/lib/apache2/modules/mod_xsendfile.so

Added this to my VirtualHost:

<VirtualHost *:80>
    XSendFile on
    XSendFilePath /path/to/protected/files/

Enabled the module by doing:

sudo a2enmod xsendfile

Then I restarted Apache. Then this code still just provides me with an empty file with 0 bytes:

file_path = '/path/to/protected/files/some_file.zip'
file_name = 'some_file.zip'
response = HttpResponse('', mimetype='application/zip')
response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)
response['X-Sendfile'] = smart_str(file_path)
return response

And there is not in the Apache error log that pertains to XSendFile. What am I doing wrong?


I got my code to work. The only difference is:

def serve_file(request, file):
    response = HttpResponse(mimetype='application/force-download')
    response['Content-Disposition'] = 'attachment; filename="%s"' % smart_str(os.path.basename(_(file.file.name)))
    response['X-Sendfile'] = smart_str(_(file.file.path))
    # It's usually a good idea to set the 'Content-Length' header too.
    # You can also set any other required headers: Cache-Control, etc.
    return response