Django/mod_wsgi on Fedora 12

I recently deployed a Django application with mod_wsgi on my server which runs Fedora 12. Since this required a bit more configuration than a standard Apache virtual host I thought it might be useful to document the configuration for others.


While SELinux can be a little annoying if you don’t understand how it works it is a very powerful security layer that should not be disabled. In order to get the Django/mod_wsgi application working I had to modify a couple of SELinux booleans which give Apache extra permissions.

setsebool httpd_tmp_exec on
setsebool httpd_can_network_connect on

mod_wsgi configuration

The default configuration tries to create the mod_wsgi sockets in a directory that SELinux does not allow Apache access to. You can change this by adding the following line to /etc/httpd/conf.d/wsgi.conf.

WSGISocketPrefix run/mod_wsgi

Apache virtual host configuration

Below is the Apache virtual host configuration. Note that I have chosen to use mod_wsgi’s daemon mode and processes instead of threads because some of the libraries I’m using are not thread safe.

<VirtualHost *:80>
 DocumentRoot /home/vhosts/

 Alias /robots.txt /home/vhosts/
 Alias /favicon.ico /home/vhosts/

 # Static files.
 Alias /static /home/vhosts/

 # Admin static files.
 Alias /media /home/vhosts/

 WSGIScriptAlias / /home/vhosts/
 WSGIDaemonProcess processes=15 threads=1 display-name=%{GROUP}

 ErrorLog logs/
 LogFormat "%a %l \"%u\" %t %m \"%U\" \"%q\" %p %>s %b %D \"%{Referer}i\" \"%{User-Agent}i\"" custom_log
 CustomLog logs/ combinedio

2 thoughts on “Django/mod_wsgi on Fedora 12

  1. Pingback: Wordpress 3.0 | Dan Siemon

Leave a Reply

Your email address will not be published. Required fields are marked *