You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/scenarios/web.rst
+91-28Lines changed: 91 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
1
+
================
1
2
Web Applications
2
3
================
3
4
@@ -13,7 +14,7 @@ The Web Server Gateway Interface (or "WSGI" for short) is a standard
13
14
interface between web servers and Python web application frameworks. By
14
15
standardizing behavior and communication between web servers and Python web
15
16
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
17
18
documented in `PEP-3333 <http://www.python.org/dev/peps/pep-3333/>`_.
18
19
19
20
@@ -76,26 +77,33 @@ Pyramid
76
77
77
78
.. todo:: Explian Pyramid
78
79
79
-
Servers
80
-
:::::::
81
-
82
-
.. todo:: Explain Apache deployment
80
+
Web Servers
81
+
:::::::::::
83
82
84
-
Apache + mod_wsgi
85
-
-----------------
83
+
Apache
84
+
------
86
85
87
-
Apache + mod_python
88
-
-------------------
86
+
mod_python
87
+
~~~~~~~~~~
89
88
90
89
For a long period Apache with mod_python was one of the most reccomended
91
90
ways to deploy Python applications and thus you may see many tutorials
92
91
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
94
93
favor of WSGI based ones.
95
94
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:
96
104
97
-
Nginx + gunicorn
98
-
----------------
105
+
Nginx
106
+
-----
99
107
100
108
`Nginx <http://nginx.org/>`_ (pronounced "engine-x") is a web server and
101
109
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
104
112
like load-balancing, basic authentication, streaming, and others. Designed
105
113
to serve high-load websites, Nginx is gradually becoming quite popular.
106
114
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
+
107
155
`gUnicorn <http://gunicorn.org/>`_ (Green Unicorn) is a WSGI server used
108
156
to serve Python applications. It is a Python fork of the Ruby
109
157
`Unicorn <http://unicorn.bogomips.org/>`_ server. gUnicorn is designed to be
110
158
lightweight, easy to use, and uses many UNIX idioms. gUnicorn is not designed
111
159
to face the internet, in fact it was designed to run behind Nginx which buffers
112
160
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>`_.
115
163
116
-
Mongrel2 + Brubeck
117
-
------------------
164
+
.. _uwsgi-ref:
118
165
119
-
.. todo:: Explain Mongrel2 + Brubeck
166
+
uwsgi
167
+
-----
120
168
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.
123
171
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.
126
175
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
+
:::::::::::::::::::::
130
178
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]_.
132
183
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/>`_.
134
188
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.
135
192
136
193
Hosting
137
194
:::::::
@@ -177,8 +234,8 @@ DotCloud
177
234
178
235
`DotCloud <http://www.dotcloud.com/>`_ supports WSGI applications and
179
236
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
182
239
for advanced users.
183
240
184
241
DotCloud uses a custom command-line API client which can work with
@@ -230,3 +287,9 @@ Twisted
230
287
231
288
232
289
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