I'm running mod_wsgi on Ubuntu Server 12.04 with Django, but I can't seem to get mod_headers working. I've run a2enmod headers, and got the response that I need to restart apache for it to work, which I have done. I added in a simple directive so that the server includes a dummy header attribute/value in response to a request, just as a test, but it's not being processed. There's no sign of it from what I can see in the net tab in Firebug.

The file that I'm requesting at the server is being accessed successfully, and it's being returned to the browser without any problems with the correct content. It just doesn't have that additional header. Here's what my /etc/apache2/sites-available/DOMAIN file looks like (but with DOMAIN replaced with my actual domain):

<VirtualHost *:80>
ServerAdmin root@DOMAIN
ServerName DOMAIN   

Alias /static/ /srv/project/app/webapp/static/
Alias /robots.txt /srv/project/app/webapp/site_media/robots.txt
Alias /favicon.ico /srv/project/app/webapp/site_media/favicon.ico

CustomLog "|/usr/sbin/rotatelogs /srv/project/logs/access.log.%Y%m%d-%H%M 60M" combined
ErrorLog "|/usr/sbin/rotatelogs /srv/project/logs/error.log.%Y%m%d-%H%M 60M"
LogLevel info

WSGIDaemonProcess DOMAIN user=rtf group=rtf processes=1 threads=15 maximum-requests=10000 python-path=/srv/project/venv/lib/python2.7/site-packages python-eggs=/srv/project/run/eggs
WSGIScriptAlias / /srv/project/app/conf/apache/django.wsgi

<Directory /srv/project/app/webapp/site_media>
Order deny,allow
Allow from all
Options -Indexes FollowSymLinks

<Directory /srv/project/app/conf/apache>
Order deny,allow
Allow from all

Header set MyHeader "It took %D microseconds for Apache to serve this request."


The "MyHeader" above is not being added to the response.

I tried to install mod_headers again in case there was any problems the first time round that I didn't know about, but a2enmod told me that it was already installed.

Incidentally, what I'm ultimately trying to achieve is to set the Content-Disposition to 'attachment' in the return header of requests for certain files, so it'll trigger a save-as dialog in the browser when a GET is made for files matching a certain pattern.

Can anyone suggest what the problem might be?

1 Answer 1


I got it working. The reason it didn't before was actually nothing to do with the configuration itself, but because I had only got the config (posted in the question) located in /etc/apache2/sites-available/

So I added it into /etc/apache2/sites-enabled/ as well, and the new headers are being picked up just fine. As it happens, forcing the Content-Disposition is having no effect on the browser i.e. when the client makes a GET request that sets the Content-Disposition to attachment, the browser still refuses to open a save-as dialog.

Looks like I'm gonna have to dynamically insert a hyperlink into the webpage with the download attribute set and try to force a click on the link programmatically. But that's a separate issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.