Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache 2 + mod_wsgi + WSGIScriptAlias

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?

like image 214
psgels Avatar asked Feb 06 '12 12:02

psgels


People also ask

What is Wsgiscriptalias?

Description: Maps a URL to a filesystem location and designates the target as a WSGI script.

What is mod_wsgi in Apache?

mod_wsgi is an Apache HTTP Server module by Graham Dumpleton that provides a WSGI compliant interface for hosting Python based web applications under Apache. As of version 4.5. 3, mod_wsgi supports Python 2 and 3 (starting from 2.6 and 3.2).

Where is mod_wsgi so?

If installing the Apache module by hand, the file is called 'mod_wsgi.so'. The compiled Apache module can be found in the “. libs” subdirectory.


1 Answers

Try:

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

You shouldn't have trailing slash on first argument.

like image 97
Graham Dumpleton Avatar answered Oct 20 '22 00:10

Graham Dumpleton