WebFaction
Community site: login faq
1
1

I would like to use Django's permission system to serve static media only to authenticated users, similar to this question or this one. Both answers point to a Webfaction forum post which no longer exists. Is there any newer information?

Django guides say to do this with the XSendFile module for Apache, which needs to be installed by a server admin or compiled according to those lost directions... Thanks!

asked 26 Jan '13, 05:16

tbern
13114
accept rate: 0%

edited 26 Jan '13, 05:20


Here are the instructions to compile mod_xsendfile and install into your existing apache based application. Get the source and unpack it in a temporary src directory.

wget --no-check-certificate 'https://tn123.org/mod_xsendfile/mod_xsendfile-0.12.tar.gz'
tar xvfz mod_xsendfile-0.12.tar.gz
cd mod_xsendfile-0.12

Compile the source using apxs:

/usr/sbin/apxs -c mod_xsendfile.c

Link the object file:

ld -Bshareable -o mod_xsendfile.so mod_xsendfile.o

Copy mod_xsndfile.so to your local Apache modules folder.

cp ~/src/mod_xsendfile-0.12/mod_xsendfile.so ~/webapps/<your application>/apache2/modules

Modify your httpd.conf to load the module:

LoadModule xsendfile_module modules/mod_xsendfile.so

Enable XSendFile and specify the path in your httpd.conf:

XSendFile on
XSendFilePath /full/path/to/those/files/I/wanna/send/
permanent link

answered 26 Jan '13, 12:11

timg ♦♦
1.3k4
accept rate: 30%

edited 26 Jan '13, 12:14

Worked like a charm!

(02 Feb '13, 19:03) tbern
1

Webfaction has removed the apxs script from /usr/sbin/apxs since the above was written. Ryan S told me: "Trying to build a module using a version of apxs which is different from your django's private Apache instance can cause difficult-to-find incompatibility errors. Instead, we would recommend building a temporary copy of apache of the exact same version as the apache that's running your Django instance, and use the apxs application from that. You can then delete the temporary installation after building the module you need."

The basic approach for doing this is at http://docs.webfaction.com/software/home-install.html.

Here are the exact steps that worked for me:

Got the version number (which for me is 2.2.17) with:

~/webapps/(webappname)/apache2/bin/httpd -v

Downloaded the nearest version number I can find (2.2.25) from a mirror site, e.g.:

wget http://mirror.nexcess.net/apache/httpd/httpd-2.2.25.tar.gz
tar xvfz httpd-2.2.25.tar.gz

Made a tmp directory:

mkdir ~/tmp/apache

Ran configure and make:

cd httpd-2.2.25
./configure --prefix=$HOME/tmp/apache
make
make install

I compiled mod_xsendfile:

~/tmp/apache/bin/apxs -c mod_xsendfile.c
(13 Aug '13, 18:54) Arty

In case it helps, I've described here the overall process I went through to serve private files with xsendfile and Django.

(14 Aug '13, 20:15) Arty

FYI - tbern's instructions are still valid, but you need to add APR to your Apache download first. See http://stackoverflow.com/a/9436971 for more info

(18 Dec '15, 09:31) pjrobertson

A complete walk-through combining all answers above can be found at: https://community.webfaction.com/questions/20487/installing-apache-module-xsendfile-for-django

permanent link

answered 12 Dec '16, 06:45

lspee
113
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×901
×222
×6
×5

question asked: 26 Jan '13, 05:16

question was seen: 19,401 times

last updated: 12 Dec '16, 06:45

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2016 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM