Django, Redmine both on the same vhost in apache

I’ve spent a good portion of my day messing with this, asking questions in various channels on, and generally trying to not let my head explode.

What ‘this’ is exactly is this:

I wanted my django app to run on / of my domain. Since I don’t own my domain it would be easiest(or so I thought) to setup redmine on /redmine of my domain. This way it is only one domain and I can run my bug/project tracker on the same place as my website.

That shows that I have it all working, now how did I do it… It will be simple for you but was not a simple process for me due to a couple settings I had tweaked without realizing the effect.

First off lets get the django app setup, I use mod_wsgi for my django apps, and run them in daemon mode so I can easily update the app without taking down the server at all.

My wsgi file (should look pretty typical for those who have seen one before):

import os
import sys

root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

os.environ['DJANGO_SETTINGS_MODULE'] = 'recipes.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

You’ll need to toss

LoadModule wsgi_module modules/

into your httpd.conf

Here is my vhost stuff without the Redmine stuff in it:

<virtualhost 80="">

Alias /media /srv/wsgi/recipes/media

<directory srv="" wsgi="" recipes="" media="">
Order allow,deny
Options Indexes FollowSymlinks
Allow from all

WSGIDaemonProcess recipes python-path=/srv/wsgi/recipes/lib/python2.6/site-packages display-name=%{GROUP}
WSGIProcessGroup recipes
WSGIScriptAlias / /srv/wsgi/recipes/recipes.wsgi

<directory srv="" wsgi="" recipes="">
Order deny,allow
Allow from all

So far this should look pretty typical for anyone who has ever setup a django vhost with apache.

Now for Redmine I chose to use Phusion, why you might ask? Well sycopomp uses it and when I asked him why, because he found a guide somewhere that made it easy and his memory usage isn’t very high. So basically, not for any good reason.

Go ahead and symlink your redmine/public directory into your DocumentRoot for me that was /srv/http.

You’ll have to install Phusion:

gem install passenger

That will toss up a helpful wizard to do the installation for you with a couple of prompts. You will need to copy the lines from the wizard into your httpd.conf, they should look something like:

LoadModule passenger_module /usr/lib/ruby/gems/1.9.1/gems/passenger-2.2.9/ext/apache2/
PassengerRoot /usr/lib/ruby/gems/1.9.1/gems/passenger-2.2.9
PassengerRuby /usr/bin/ruby

Next we need to add a line to our vhost and change another one, first line we’ll add tells the server where to find and put redmine:

RailsBaseURI /redmine

And secondly we need to change out:

WSGIScriptAlias / /srv/wsgi/recipes/recipes.wsgi

Add put in the following instead since that will make django not catch /redmine:

WSGIScriptAliasMatch ^\/(?!redmine(.*)) /srv/wsgi/recipes/recipes.wsgi

Restart the server and we should be good.

I didn’t make this page/code as generic as I could have but hopefully you can get the meaning from it, if not the kind folks in #httpd on can help you. They’ll understand this if you don’t. Also, do what some like to call frobbing, play with it, break it, whatever it takes so you understand it.

3 thoughts on “Django, Redmine both on the same vhost in apache

  1. Are you sure that works? Because you don't add back the matched pattern for WSGIScriptAliasMatch to final argument, I would suspect that SCRIPT_NAME/PATH_INFO may not be calculated properly when request goes through to Django.

  2. Graham:This is currently working on a couple sites on my server, whether this *should* be working I can't attest to as this is what works for me so I stopped looking any further into it.

Leave a Reply to Graham Dumpleton Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s