From ArchWiki
Jump to: navigation, 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 and high performance web applications.

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. 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 modifying the formers.



Two packages are present in community:

  • mod_wsgi provides the module works with all common versions of Python (3.x)
  • mod_wsgi2 provides the module can only run with 2.x versions of Python

When you use mod_wsgi with Python 2.x better to install mod_wsgi2.

Apache configuration

As indicated during installation, add the following line to the configuration file of Apache:

LoadModule wsgi_module modules/

Restart Apache:

systemctl restart httpd

Check that Apache is running properly. If the previous command returned nothing, it means that the launch of Apache went well. Otherwise, you can see errors with the following command:

systemctl -l status httpd.service

Module test

Add this line in Apache configuration file:

WSGIScriptAlias /wsgi_app /srv/http/

Create a test file:

#-*- coding: utf-8 -*-
def wsgi_app(environ, start_response):
    import sys
    output = sys.version.encode('utf8')
    status = '200 OK'
    headers = [('Content-type', 'text/plain'),
               ('Content-Length', str(len(output)))]
    start_response(status, headers)
    yield output

# mod_wsgi need the *application* variable to serve our small app
application = wsgi_app

Restart Apache:

systemctl restart httpd

You can check the proper functioning by going to the following address : http://localhost/wsgi_app

See Also