HowToPythonWSGI » History » Revision 1
Revision 1/6
| Next »
gstrauss, 2016-09-25 08:26
HowToPythonWSGI¶
Background: What is WSGI?¶
The official WSGI documentation (http://wsgi.readthedocs.io/en/latest/) has the following definition of WSGI at
http://wsgi.readthedocs.io/en/latest/what.html
WSGI is the Web Server Gateway Interface. It is a specification that describes how a web server communicates with web applications, and how web applications can be chained together to process one request.
The above would be much clearer if it stated that WSGI is "a specification that describes how a Python-capable web server communicates with Python web applications running within the Python server. WSGI describes an API in Python for the Python interpreter to run a callable Python function (which implements a web app) to handle a request, and for how that Python function responds to the request.
If a web server is a Python-based web server or has an embedded Python interpreter built into the web server, then the web server can implement WSGI API within the web server process. If not, then the web server must use a different gateway protocol (HTTP, CGI, FastCGI, SCGI, uwsgi, ...) to communicate to a Python process (which supports that same gateway protocol), and then the Python process can translate the request from the gateway protocol to the WSGI API.
lighttpd and Python WSGI¶
lighttpd is single-threaded and does not have any plans to build an embedded Python interpreter into the lighttpd server since arbitrary Python application code can cause the entire lighttpd server to block. Therefore, lighttpd must use another gateway protocol to run Python applications which implement the WSGI API.- HTTP: lighttpd can use mod_proxy to connect to a Python server via HTTP
- FastCGI: lighttpd can use mod_fastcgi to connect to a Python server via FastCGI
- SCGI: lighttpd can use mod_scgi to connect to a Python server via SCGI (
scgi.protocol = "scgi"
(default)) - uwsgi: lighttpd can use mod_scgi to connect to a Python server via uwsgi (
scgi.protocol = "uwsgi"
(since lighttpd 1.4.42)) - CGI: lighttpd can use mod_cgi to start a Python program via CGI
A Python server must be run as an independent process to serve a Python WSGI application (unless lighttpd is configured to run the Python process as a CGI). There are many Python servers which support one or more of the above protocols and also support Python WSGI applications. The WSGI website lists some Python servers at http://wsgi.readthedocs.io/en/latest/servers.html
Updated by gstrauss about 8 years ago · 1 revisions