< Apache HTTP Server

Apache HTTP Server/mod_wsgi

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.

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.

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

gollark: I may be missing something but it looks like you could just use an array for `o`.
gollark: I don't trust it to not explode my computer or something.
gollark: You probably want webpack or something. Although good luck actually configuring webpack. Or just create-react-app.
gollark: babel is a separate thing you can use with react.
gollark: Neither, I'm pretty sure.
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.