Apache HTTP Server/mod_wsgi

From ArchWiki

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 HTTP Server 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.

Example:

Installation

Install mod_wsgiAUR which provides the module working with all common versions of Python (3.x).

Apache configuration

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

/etc/httpd/conf/httpd.conf
LoadModule wsgi_module modules/mod_wsgi.so

Restart httpd.service.

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 httpd.service unit status.

Module test

Add this line in Apache configuration file:

/etc/httpd/conf/httpd.conf
WSGIScriptAlias /wsgi_app /srv/http/wsgi_app.py

Create a test file:

/srv/http/wsgi_app.py
#-*- 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 httpd.service

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

See Also