Apache 2 + mod_wsgi + WSGIScriptAlias

psgels picture psgels · Feb 6, 2012 · Viewed 16.3k times · Source

I am currently doing research whether Python and Django are fit for a project that I'm going to work on (so far it looks good). As a means of a test, I want to get python running on an actual server (apache2 on ubuntu), using mod_wsgi, but I just can't make it work. Here is my httpd.conf (located at /etc/apache2/httpd.conf):

WSGIScriptAlias /test/tc-test/ /var/www/stage/hello/tc-test/django.wsgi
WSGIPythonPath /var/www/stage/test/tc-test/

<Directory /var/www/stage/test/tc-test>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

My django.wsgi looks as follows:

import os
import sys

sys.path.append('/var/www/stage/test/tc-test')

os_environment['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi

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

The url for this directory will be http://stage.website.com/test/tc-test

Strangely enough, when I reboot the apache server, I keep getting 500 internal server errors. Not just for that subdirectory, but for all other subdirectories on the server. I looked at the apache error log, but for some reason no error is being logged at all. I managed to narrow down the culprits to WSGIScriptAlias and WSGIPythonPath: when I remove both of them, the 500 internal server errors disappear, and when I add any of them, they appear again. I have confirmed that mod_wsgi is working like it should, and it's probably something very simple that I'm looking over. I just can't find out what. Any help on this?

Answer

Graham Dumpleton picture Graham Dumpleton · Feb 7, 2012

Try:

WSGIScriptAlias /test/tc-test /var/www/stage/hello/tc-test/django.wsgi

You shouldn't have trailing slash on first argument.