[PATCH] Add WSGI Handler

martin f. krafft madduck at madduck.net
Sun Jan 31 12:40:01 EST 2010


Patchwork/Django can be run directly with WSGI, which is bound to be
faster and less complex than FastCGI. This patch provides the necessary
Apache configuration and the WSGI handler, as well as an update to the
docs.

Since python-flup is deprecated and WSGI supersedes FastCGI, it should
be(come) the preferred method. Hence I documented it first.

Signed-off-by: martin f. krafft <madduck at madduck.net>
---
 docs/INSTALL                    |   16 +++++++++++++-
 lib/apache2/patchwork.wsgi      |   35 ++++++++++++++++++++++++++++++++++
 lib/apache2/patchwork.wsgi.conf |   40 +++++++++++++++++++++++++++++++++++++++
 patchwork.wsgi                  |    1 +
 4 files changed, 90 insertions(+), 2 deletions(-)
 create mode 100644 lib/apache2/patchwork.wsgi
 create mode 100644 lib/apache2/patchwork.wsgi.conf
 create mode 120000 patchwork.wsgi

diff --git a/docs/INSTALL b/docs/INSTALL
index 3cd001e..dd31f32 100644
--- a/docs/INSTALL
+++ b/docs/INSTALL
@@ -133,10 +133,22 @@ in brackets):
 
 Example apache configuration files are in lib/apache/.
 
+wsgi:
+	django has built-in support for WSGI, which supersedes the fastcgi
+	handler. It is thus the preferred method to run patchwork.
+
+	The necessary configuration for Apache2 may be found in
+	lib/apache2/patchwork.wsgi.conf.
+
+	You will need to install/enable mod_wsgi for this to work:
+
+	 a2enmod wsgi
+	 apache2ctl restart
+
 mod_python:
 
-	This should be the simpler of the two to set up. An example apache
-	configuration file is in:
+	This should be the simplest to set up. An example apache configuration
+	file is in:
 
 	  lib/apache/patchwork.mod_python.conf
 
diff --git a/lib/apache2/patchwork.wsgi b/lib/apache2/patchwork.wsgi
new file mode 100644
index 0000000..6c69cd1
--- /dev/null
+++ b/lib/apache2/patchwork.wsgi
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+#
+# Apache2 WSGI handler for patchwork
+#
+# Copyright © 2010 martin f. krafft <madduck at madduck.net>
+# Released under the terms of the Artistic Licence 2.0
+#
+import os, sys
+
+basedir = os.path.dirname(__file__)
+sys.path.append(basedir)
+
+os.environ['DJANGO_SETTINGS_MODULE'] = 'apps.settings'
+import django.core.handlers.wsgi
+application = django.core.handlers.wsgi.WSGIHandler()
+
+#from django.conf import settings
+#if settings.DEBUG:
+#    print >> sys.stderr, "Using Paste error middleware"
+#    from paste.exceptions.errormiddleware import ErrorMiddleware
+#    application = ErrorMiddleware(application, debug=True, show_exceptions_in_wsgi_errors=True)
+
+def _application(environ, start_response):
+    status = '200 OK'
+    output = 'Hello World!'
+
+    print >> environ['wsgi.errors'], "application debug #1"
+
+    response_headers = [('Content-type', 'text/plain'),
+                        ('Content-Length', str(len(output)))]
+    start_response(status, response_headers)
+
+    print >> environ['wsgi.errors'], "application debug #2"
+
+    return [output]
diff --git a/lib/apache2/patchwork.wsgi.conf b/lib/apache2/patchwork.wsgi.conf
new file mode 100644
index 0000000..64d3f78
--- /dev/null
+++ b/lib/apache2/patchwork.wsgi.conf
@@ -0,0 +1,40 @@
+Alias /media/ "/srv/patchwork/htdocs/media/"
+<Directory "/srv/patchwork/htdocs/media">
+  Order allow,deny
+  Allow from all
+</Directory>
+
+Alias /css/ "/srv/patchwork/htdocs/css/"
+<Directory "/srv/patchwork/htdocs/css">
+  Order allow,deny
+  Allow from all
+</Directory>
+
+Alias /js/ "/srv/patchwork/htdocs/js/"
+<Directory "/srv/patchwork/htdocs/js">
+  Order allow,deny
+  Allow from all
+</Directory>
+
+Alias /admin/media/ "/usr/share/python-support/python-django/django/contrib/admin/media/"
+<Directory "/usr/share/python-support/python-django/django/contrib/admin/media/">
+  Order allow,deny
+  Allow from all
+</Directory>
+
+<Directory "/srv/patchwork/">
+  Order allow,deny
+  Allow from all
+  Options SymlinksIfOwnerMatch
+</Directory>
+
+WSGIScriptAlias / "/srv/patchwork/patchwork.wsgi"
+
+ProxyPass /dev/ http://localhost:8000/
+ProxyPassReverse /dev/ http://localhost:8000/
+
+ProxyVia On
+<ProxyMatch http://localhost:8000/.*>
+  Order deny,allow
+  Allow from all
+</ProxyMatch>
diff --git a/patchwork.wsgi b/patchwork.wsgi
new file mode 120000
index 0000000..cf13d18
--- /dev/null
+++ b/patchwork.wsgi
@@ -0,0 +1 @@
+lib/apache2/patchwork.wsgi
\ No newline at end of file
-- 
1.5.6.5



More information about the Patchwork mailing list