mod_wsgi is an Apache module that provides a WSGI compliant interface for hosting Python based web applications within Apache. The adapter is written completely in C code against the Apache C runtime and for hosting WSGI applications within Apache has a lower overhead than using existing WSGI adapters for mod_python or CGI. Check out the
documentation for more details. There is no stable release but you can get the code from SVN repository and compile it.
Get the code from SVN:
svn checkout http://modwsgi.googlecode.com/svn/trunk/ modwsgi
Compile and install:
./configure
make
make install
mod_wsgi is ready.
Create
hello.py file with the code:
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
In apache configuration set:
LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias / /path/to/hello.py
Now when you start the server you should see on http://localhost/ the "Hello World!" message.
Here is a configuration for a django project:
Alias /site_media/ "/path/to/djangoproject/site_media/"
LoadModule wsgi_module modules/mod_wsgi.so
<Directory /path/to/djangoproject/site_media>
Order deny,allow
Allow from all
</Directory>
WSGIScriptAlias / /path/to/djangoproject/mysite.wsgi
<Directory /path/to/djangoproject>
Order deny,allow
Allow from all
</Directory>
mysite.wsgi:
import os, sys
sys.path.append('/path/to/djangoproject/')
# may be required :)
#sys.path.append('/path/to/')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I've made simple Siege tests for Apache 2.0.59, Python 2.4.4 and mod_python 3.3.1 under AMD64 Gentoo using my site (Django) as the test application. The charts show the results. mod_wsgi is bit faster than mod_python even now. Transaction rate for mod_python and mod_wsgi: 16,79 and 18,63 transactions per second (3 Siege tests, standard deviation: 1,89 and 0,4). Throughput 0,11 and 0,12 MB per second (standard deviation: 0,02 and 0) and average response time: 0,37 and 0,3 seconds (standard deviation: 0,07 and 0,03)
- Added: 14.07.2008 by riklaunim