Apache HTTP Server/mod wsgi

From ArchWiki
< Apache HTTP Server
Revision as of 20:46, 22 November 2009 by Tcourbon (talk | contribs) (Created page with 'Category:Networking (English) Category:HOWTOs (English) ==Introduction== According to the [http://code.google.com/p/modwsgi/ project's site] : ::The aim of mod_wsgi is t…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


According to the project's site :

The aim of mod_wsgi is to implement a simple to use Apache module which can host any Python application which supports the Python WSGI interface. The module would be suitable for use in hosting high performance production web sites, as well as your average self managed personal sites running on web hosting services.

mod_wsgi is an Apache module that embeds a Python application within the server and allow them to communicate through the Python WSGI interface as defined in the Python PEP 333. WSGI is one of the Python ways to produce high quality & performance web application.

WSGI provide a standard way to interface different web-apps without hassle. Several well-know python applications or frameworks provide wsgi for easy deployment and embedding into other wsgi apps. It means that you can embed your Django-powered blog and your project's Trac into a single Pylons application that wraps around them to deals with, say, authentication without touching the formers.


mod_wsgi support those Python version: 2.5, 2.6, 3.1 (remember developers had dropped support for 3.0).


Apache Module : mod_wsgi

This document describes how to set up and test the Apache module mod_wsgi on an Arch Linux system.

Install Package

The mod_wsgi package live in extra, install it with pacman (or whatever you want) :

# pacman -Sy mod_wsgi

Configure Apache

  • As requested by the installer, add the following line to /etc/httpd/conf/httpd.conf:
LoadModule wsgi_module modules/mod_wsgi.so
  • Restart Apache
# /etc/rc.d/httpd restart
  • Check to make sure that Apache loaded correctly

Test mod_wsgi

  • Add this block to /etc/httpd/conf/httpd.conf:
WSGIScriptAlias /wsgi_app /home/www/wsgi-scripts/wsgi_app.py

<Directory /home/www/wsgi-scripts>
    Order allow,deny
    Allow from all
  • Create a file in /home/www/wsgi-scripts called wsgi_app.py with this code :
#-*- coding: utf-8 -*-
import pprint
def wsgi_app(environ, start_response):
    """ Display the contents of the environ dictionary."""
    # produce some content
    output =  pprint.pformat(environ)

    # send first header and status
    status = '200 OK'
    headers = [('Content-type', 'text/plain'),
		('Content-Length', str(len(output)))]
    start_response(status, headers)

    # wsgi apps should return and iterable, the following is acceptable too :
    # return [output]
    yield output

# mod_wsgi need the *application* variable to serve our small app
application = wsgi_app
  • Restart Apache
# /etc/rc.d/httpd  restart
  • Check to make sure that Apache loaded correctly
Example: mod_python allow you to execute arbitrary Python script that end with .py. mod_wsgi behave another way : it only serve application and isn't an handler as mod_wsgi.

See Also