Skip to content

Commit a150dbe

Browse files
committed
Updated notes on Apache and added web server best practices
1 parent 1df22ab commit a150dbe

File tree

1 file changed

+91
-28
lines changed

1 file changed

+91
-28
lines changed

docs/scenarios/web.rst

Lines changed: 91 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
================
12
Web Applications
23
================
34

@@ -13,7 +14,7 @@ The Web Server Gateway Interface (or "WSGI" for short) is a standard
1314
interface between web servers and Python web application frameworks. By
1415
standardizing behavior and communication between web servers and Python web
1516
frameworks, WSGI makes it possible to write portable Python web code that
16-
can be deployed in any `WSGI-compliant web server <#servers>`_. WSGI is
17+
can be deployed in any :ref:`WSGI-compliant web server <wsgi-servers-ref>`. WSGI is
1718
documented in `PEP-3333 <http://www.python.org/dev/peps/pep-3333/>`_.
1819

1920

@@ -76,26 +77,33 @@ Pyramid
7677

7778
.. todo:: Explian Pyramid
7879

79-
Servers
80-
:::::::
81-
82-
.. todo:: Explain Apache deployment
80+
Web Servers
81+
:::::::::::
8382

84-
Apache + mod_wsgi
85-
-----------------
83+
Apache
84+
------
8685

87-
Apache + mod_python
88-
-------------------
86+
mod_python
87+
~~~~~~~~~~
8988

9089
For a long period Apache with mod_python was one of the most reccomended
9190
ways to deploy Python applications and thus you may see many tutorials
9291
about it on the web or in books, however Apache no longer supports
93-
mod_python and thus this deployment mechanism is strongly discouraged in
92+
mod_python [1]_ and thus this deployment mechanism is strongly discouraged in
9493
favor of WSGI based ones.
9594

95+
mod_wsgi
96+
~~~~~~~~
97+
98+
Many improvements have been made with mod_wsgi over mod_python for serving
99+
Python with Apache [2]_. If you must run the Apache web server, mod_wsgi is
100+
your best option for running Python, other than proxying to a dedicated WSGI
101+
server.
102+
103+
.. _nginx-ref:
96104

97-
Nginx + gunicorn
98-
----------------
105+
Nginx
106+
-----
99107

100108
`Nginx <http://nginx.org/>`_ (pronounced "engine-x") is a web server and
101109
reverse-proxy for HTTP, SMTP and other protocols. It is known for its
@@ -104,34 +112,83 @@ application servers (like WSGI servers). It also includes handy features
104112
like load-balancing, basic authentication, streaming, and others. Designed
105113
to serve high-load websites, Nginx is gradually becoming quite popular.
106114

115+
Mongrel2
116+
--------
117+
118+
`Mongrel2 <http://mongrel2.org>`_ is an application, language, and network
119+
architecture agnostic web server. It uses a high performance queue (zeromq) to
120+
communicate with your applications, all asynchronously. There is a well defined
121+
protocol to be used between mongrel2 and a backend handler (your app).
122+
123+
Brubeck
124+
~~~~~~~
125+
126+
.. todo:: Explain Mongrel2 + Brubeck
127+
128+
wsgid
129+
~~~~~
130+
131+
`Wsgid <http://wsgid.com>`_ is a generic mongrel2 handler that speaks both
132+
mongrel2 protocol and WSGI. This makes it possible to run your python webapp
133+
written with any WSGI compliant framework. Wsgid has built-in Django support but
134+
has also a generic way to load your WSGI application object directly. It's
135+
possible to add support for other frameworks through wsgid's pluggable
136+
Apploading interface.
137+
138+
.. rubric:: Resources
139+
140+
* `Deploying your django application with mongrel2 and wsgid <http://daltonmatos.wordpress.com/2011/11/06/deploying-your-django-application-with-mongrel2-and-wsgid/>`_
141+
142+
.. _wsgi-servers-ref:
143+
144+
WSGI Servers
145+
::::::::::::
146+
147+
Stand-alone WSGI servers typically use less resources than traditional web
148+
servers and provide top performance [3]_.
149+
150+
.. _gunicorn-ref:
151+
152+
gUnicorn
153+
--------
154+
107155
`gUnicorn <http://gunicorn.org/>`_ (Green Unicorn) is a WSGI server used
108156
to serve Python applications. It is a Python fork of the Ruby
109157
`Unicorn <http://unicorn.bogomips.org/>`_ server. gUnicorn is designed to be
110158
lightweight, easy to use, and uses many UNIX idioms. gUnicorn is not designed
111159
to face the internet, in fact it was designed to run behind Nginx which buffers
112160
slow requests, and takes care of other important considerations. A sample
113-
setup for Nginx + gUnicorn can be found in the gUnicorn
114-
`help <http://gunicorn.org/deploy.html>`_.
161+
setup for Nginx + gUnicorn can be found in the
162+
`gUnicorn help <http://gunicorn.org/deploy.html>`_.
115163

116-
Mongrel2 + Brubeck
117-
------------------
164+
.. _uwsgi-ref:
118165

119-
.. todo:: Explain Mongrel2 + Brubeck
166+
uwsgi
167+
-----
120168

121-
Mongrel2 + wsgid
122-
----------------
169+
`uWSGI <http://projects.unbit.it/uwsgi/>`_ is a fast, self-healing and
170+
developer/sysadmin-friendly application container server coded in pure C.
123171

124-
Mongrel2 is an application, language, and network architecture agnostic web server. It uses a high performance queue (zeromq) to communicate
125-
with your applications, all asynchronously. There is a well defined protocol to be used between mongrel2 and a backend handler (your app).
172+
Born as a WSGI-only server, over time it has evolved in a complete stack for
173+
networked/clustered web applications, implementing message/object passing,
174+
caching, RPC and process management.
126175

127-
Wsgid is a generic mongrel2 handler that speaks both mongrel2 protocol and WSGI. This makes it possible to run your python webapp written with any
128-
WSGI compliant framework. Wsgid has built-in Django support but has also a generic way to load your WSGI application object directly. It's possible
129-
to add support for other frameworks through wsgid's pluggable Apploading interface.
176+
Server Best Practices
177+
:::::::::::::::::::::
130178

131-
To know more about mongrel2 and wsgid go to: http://mongrel2.org and http://wsgid.com
179+
While Apache will serve your Python application, and many references suggest it,
180+
modern best practices suggest against it. With the improvements in mod_wsgi over
181+
mod_python, Apache can handle many more requests than before. However, mod_wsgi
182+
tends to use more memory than other WSGI solutions [3]_.
132183

133-
There is also a tutorial about deploying Django using this stack: http://daltonmatos.wordpress.com/2011/11/06/deploying-your-django-application-with-mongrel2-and-wsgid/
184+
The majority of self hosted Python applications today are hosted with a WSGI
185+
server such as :ref:`uWSGI <uwsgi-ref>` or :ref:`gUnicorn <gunicorn-ref>` behind a
186+
lightweight web server such as :ref:`nginx <nginx-ref>` or
187+
`lighttpd <http://www.lighttpd.net/>`_.
134188

189+
The WSGI servers serve the Python applications while the web server handles tasks
190+
better suited for it such as static file serving, request routing, DDoS
191+
protection, and basic authentication.
135192

136193
Hosting
137194
:::::::
@@ -177,8 +234,8 @@ DotCloud
177234

178235
`DotCloud <http://www.dotcloud.com/>`_ supports WSGI applications and
179236
background/worker tasks natively on their platform. Web applications running
180-
Python version 2.6, and uses `nginx <http://nginx.org/>`_ and `uWSGI
181-
<http://projects.unbit.it/uwsgi/>`_, and allows custom configuration of both
237+
Python version 2.6, and uses :ref:`nginx <nginx-ref>` and :ref:`uWSGI
238+
<uwsgi-ref>`, and allows custom configuration of both
182239
for advanced users.
183240

184241
DotCloud uses a custom command-line API client which can work with
@@ -230,3 +287,9 @@ Twisted
230287

231288

232289
Node.js.
290+
291+
.. rubric:: References
292+
293+
.. [1] `The mod_python project is now officially dead <http://blog.dscpl.com.au/2010/06/modpython-project-is-now-officially.html>`_
294+
.. [2] `mod_wsgi vs mod_python <http://www.modpython.org/pipermail/mod_python/2007-July/024080.html>`_
295+
.. [3] `Benchmark of Python WSGI Servers <http://nichol.as/benchmark-of-python-web-servers>`_

0 commit comments

Comments
 (0)