Skip to content

Commit 2256750

Browse files
committed
converting wsgi servers section to markdown
1 parent 609e91a commit 2256750

File tree

3 files changed

+108
-115
lines changed

3 files changed

+108
-115
lines changed

feeds/all.atom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<feed xmlns="http://www.w3.org/2005/Atom"><title>Matt Makai</title><link href="http://www.fullstackpython.com/" rel="alternate"></link><link href="http://www.fullstackpython.com/feeds/all.atom.xml" rel="self"></link><id>http://www.fullstackpython.com/</id><updated>2014-02-25T17:54:12Z</updated></feed>
2+
<feed xmlns="http://www.w3.org/2005/Atom"><title>Matt Makai</title><link href="http://www.fullstackpython.com/" rel="alternate"></link><link href="http://www.fullstackpython.com/feeds/all.atom.xml" rel="self"></link><id>http://www.fullstackpython.com/</id><updated>2014-02-25T18:48:52Z</updated></feed>

source/content/pages/wsgi-servers.rst renamed to source/content/pages/07-wsgi-servers/0701-wsgi-servers.markdown

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,29 @@
1-
============
2-
WSGI Servers
3-
============
4-
5-
:category: page
6-
:slug: wsgi-servers
7-
:sort-order: 07
8-
9-
------------
10-
WSGI Servers
11-
------------
12-
A `Web Server Gateway Interface <http://wsgi.readthedocs.org/en/latest/>`_
1+
title: WSGI Servers
2+
category: page
3+
slug: wsgi-servers
4+
sort-order: 07
5+
6+
7+
# WSGI Servers
8+
A [Web Server Gateway Interface](http://wsgi.readthedocs.org/en/latest/)
139
(WSGI) server implements the web server side of the WSGI interface for
1410
running Python web applications. The WSGI standard v1.0 is specified in
15-
`PEP 0333 <http://www.python.org/dev/peps/pep-0333/>`_. As of September 2010,
11+
[PEP 0333](http://www.python.org/dev/peps/pep-0333/). As of September 2010,
1612
WSGI v1.0 is superseded by
17-
`PEP 3333 <http://www.python.org/dev/peps/pep-3333/>`_, which defines the
13+
[PEP 3333](http://www.python.org/dev/peps/pep-3333/), which defines the
1814
v1.0.1 WSGI standard.
1915

20-
21-
.. image:: theme/img/web-browser-server-wsgi.png
22-
:alt: WSGI Server <-> Web server <-> Browser
23-
:width: 100%
24-
:class: technical-diagram
16+
<img src="theme/img/web-browser-server-wsgi.png" alt="WSGI Server <-> Web server <-> Browser" width="100%" class="technical-diagram" />
2517

2618
A web server's configuration specifies what requests should be passed to
2719
the WSGI server to process. Once a request is processed and generated by the
2820
WSGI server, the response is passed back through the web server and onto
29-
the browser. For example, this Nginx web server's configuration specifics
21+
the browser.
22+
23+
For example, this Nginx web server's configuration specifics
3024
Nginx should handle static assets (such as images, JavaScript, and CSS
3125
files) under the /static directory and pass all other requests to the WSGI
32-
server running on port 8000::
26+
server running on port 8000:
3327

3428
# this specifies that there is a WSGI server running on port 8000
3529
upstream app_server_djangoapp {
@@ -62,7 +56,7 @@ server running on port 8000::
6256

6357
Note that the above code is a simplified version of a production-ready Nginx
6458
configuration. For real SSL and non-SSL templates, take a look at the
65-
`Underwear web server templates <https://github.com/makaimc/underwear/tree/master/underwear/roles/web/templates>`_ on GitHub.
59+
[Underwear web server templates](https://github.com/makaimc/underwear/tree/master/underwear/roles/web/templates) on GitHub.
6660

6761
WSGI is by design a simple standard interface for running Python code. As
6862
a web developer you won't need to know much more than
@@ -80,23 +74,22 @@ If you're using a standard web framework such as Django, Flask, or
8074
Bottle, or almost any other current Python framework, you don't need to worry
8175
about how frameworks implement the application side of the WSGI standard.
8276
Likewise, if you're using a standard WSGI container such as Green Unicorn,
83-
uWSGI, mod_wsgi, or gevent, you can get them running without worrying about
77+
uWSGI, mod\_wsgi, or gevent, you can get them running without worrying about
8478
how they implement the WSGI standard.
8579

8680
However, knowing the WSGI standard and how these frameworks and containers
8781
implement WSGI should be on your learning checklist though as you become
8882
a more experienced Python web developer.
8983

9084

91-
WSGI's Purpose
92-
--------------
85+
## WSGI's Purpose
9386
Why use WSGI and not just point a web server directly at an application?
9487

9588
* **WSGI gives you flexibility**. Application developers can swap out
9689
web stack components for others. For example, a developer can switch from
9790
Green Unicorn to uWSGI without modifying the application or framework
9891
that implements WSGI.
99-
From `PEP 3333 <http://www.python.org/dev/peps/pep-3333/>`_:
92+
From [PEP 3333](http://www.python.org/dev/peps/pep-3333/):
10093

10194
The availability and widespread use of such an API in web servers for
10295
Python [...] would separate choice of framework from choice of web
@@ -112,25 +105,24 @@ Why use WSGI and not just point a web server directly at an application?
112105
web traffic.
113106

114107

115-
WSGI Resources
116-
--------------
117-
`PEP 0333 WSGI v1.0 <http://www.python.org/dev/peps/pep-0333/>`_
108+
## WSGI Resources
109+
[PEP 0333 WSGI v1.0](http://www.python.org/dev/peps/pep-0333/)
118110
and
119-
`PEP 3333 WSGI v1.0.1 <http://www.python.org/dev/peps/pep-3333/>`_
111+
[PEP 3333 WSGI v1.0.1](http://www.python.org/dev/peps/pep-3333/)
120112
specifications.
121113

122-
`Green Unicorn <http://gunicorn.org/>`_,
123-
`mod_wsgi <http://code.google.com/p/modwsgi/>`_,
124-
`uWSGI <https://github.com/unbit/uwsgi-docs>`_, and
125-
`gevent <http://www.gevent.org/>`_ are common WSGI server implementations.
114+
[Green Unicorn](http://gunicorn.org/),
115+
[mod\_wsgi](http://code.google.com/p/modwsgi/),
116+
[uWSGI](https://github.com/unbit/uwsgi-docs), and
117+
[gevent](http://www.gevent.org/) are common WSGI server implementations.
126118

127-
This `Basics of WSGI <http://agiliq.com/blog/2013/07/basics-wsgi/>`_ post
119+
This [Basics of WSGI](http://agiliq.com/blog/2013/07/basics-wsgi/) post
128120
contains a simple example of how a WSGI-compatible application works.
129121

130-
`Complete single server Django stack tutorial <http://www.apreche.net/complete-single-server-django-stack-tutorial/>`_ is thorough and informative for
131-
non-paas hosting choices.
122+
This [complete single server Django stack tutorial](http://www.apreche.net/complete-single-server-django-stack-tutorial/>)
123+
is thorough and informative for LAMP-stack hosting choices.
132124

133125
This detailed post entitled
134-
`The Beautiful Simplicity of an nginx and uWSGI Deployments <http://bartek.im/blog/2012/07/08/simplicity-nginx-uwsgi-deployment.html>`_
126+
[The Beautiful Simplicity of an nginx and uWSGI Deployments](http://bartek.im/blog/2012/07/08/simplicity-nginx-uwsgi-deployment.html)
135127
is great reading for understanding Nginx and uWSGI configurations.
136128

wsgi-servers.html

Lines changed: 77 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -74,65 +74,72 @@
7474
</div>
7575
<div class="row">
7676
<div class="col-md-8">
77-
<div class="section" id="id1">
78-
<h2>WSGI Servers</h2>
79-
<p>A <a class="reference external" href="http://wsgi.readthedocs.org/en/latest/">Web Server Gateway Interface</a>
77+
<h1>WSGI Servers</h1>
78+
<p>A <a href="http://wsgi.readthedocs.org/en/latest/">Web Server Gateway Interface</a>
8079
(WSGI) server implements the web server side of the WSGI interface for
8180
running Python web applications. The WSGI standard v1.0 is specified in
82-
<a class="reference external" href="http://www.python.org/dev/peps/pep-0333/">PEP 0333</a>. As of September 2010,
81+
<a href="http://www.python.org/dev/peps/pep-0333/">PEP 0333</a>. As of September 2010,
8382
WSGI v1.0 is superseded by
84-
<a class="reference external" href="http://www.python.org/dev/peps/pep-3333/">PEP 3333</a>, which defines the
83+
<a href="http://www.python.org/dev/peps/pep-3333/">PEP 3333</a>, which defines the
8584
v1.0.1 WSGI standard.</p>
86-
<img alt="WSGI Server &lt;-&gt; Web server &lt;-&gt; Browser" class="technical-diagram" src="theme/img/web-browser-server-wsgi.png" style="width: 100%;" />
85+
<p><img src="theme/img/web-browser-server-wsgi.png" alt="WSGI Server <-> Web server &lt;-&gt; Browser" width="100%" class="technical-diagram" /&gt;</p>
8786
<p>A web server's configuration specifies what requests should be passed to
8887
the WSGI server to process. Once a request is processed and generated by the
8988
WSGI server, the response is passed back through the web server and onto
90-
the browser. For example, this Nginx web server's configuration specifics
89+
the browser. </p>
90+
<p>For example, this Nginx web server's configuration specifics
9191
Nginx should handle static assets (such as images, JavaScript, and CSS
9292
files) under the /static directory and pass all other requests to the WSGI
9393
server running on port 8000:</p>
94-
<pre class="literal-block">
95-
# this specifies that there is a WSGI server running on port 8000
96-
upstream app_server_djangoapp {
97-
server localhost:8000 fail_timeout=0;
98-
}
94+
<div class="codehilite"><pre><span class="c"># this specifies that there is a WSGI server running on port 8000</span>
95+
<span class="n">upstream</span> <span class="n">app_server_djangoapp</span> <span class="p">{</span>
96+
<span class="n">server</span> <span class="n">localhost</span><span class="p">:</span>8000 <span class="n">fail_timeout</span><span class="p">=</span>0<span class="p">;</span>
97+
<span class="p">}</span>
9998

100-
# Nginx is set up to run on the standard HTTP port and listen for requests
101-
server {
102-
listen 80;
99+
<span class="c"># Nginx is set up to run on the standard HTTP port and listen for requests</span>
100+
<span class="n">server</span> <span class="p">{</span>
101+
<span class="n">listen</span> 80<span class="p">;</span>
103102

104-
# nginx should serve up static files and never send to the WSGI server
105-
location /static {
106-
autoindex on;
107-
alias /srv/www/assets;
108-
}
103+
<span class="c"># nginx should serve up static files and never send to the WSGI server</span>
104+
<span class="n">location</span> <span class="o">/</span><span class="k">static</span> <span class="p">{</span>
105+
<span class="n">autoindex</span> <span class="n">on</span><span class="p">;</span>
106+
<span class="n">alias</span> <span class="o">/</span><span class="n">srv</span><span class="o">/</span><span class="n">www</span><span class="o">/</span><span class="n">assets</span><span class="p">;</span>
107+
<span class="p">}</span>
108+
109+
<span class="c"># requests that do not fall under /static are passed on to the WSGI</span>
110+
<span class="c"># server that was specified above running on port 8000</span>
111+
<span class="n">location</span> <span class="o">/</span> <span class="p">{</span>
112+
<span class="n">proxy_set_header</span> <span class="n">X</span><span class="o">-</span><span class="n">Forwarded</span><span class="o">-</span><span class="n">For</span> $<span class="n">proxy_add_x_forwarded_for</span><span class="p">;</span>
113+
<span class="n">proxy_set_header</span> <span class="n">Host</span> $<span class="n">http_host</span><span class="p">;</span>
114+
<span class="n">proxy_redirect</span> <span class="n">off</span><span class="p">;</span>
115+
116+
<span class="k">if</span> <span class="p">(</span><span class="o">!-</span><span class="n">f</span> $<span class="n">request_filename</span><span class="p">)</span> <span class="p">{</span>
117+
<span class="n">proxy_pass</span> <span class="n">http</span><span class="p">:</span><span class="o">//</span><span class="n">app_server_djangoapp</span><span class="p">;</span>
118+
<span class="k">break</span><span class="p">;</span>
119+
<span class="p">}</span>
120+
<span class="p">}</span>
121+
<span class="p">}</span>
122+
</pre></div>
109123

110-
# requests that do not fall under /static are passed on to the WSGI
111-
# server that was specified above running on port 8000
112-
location / {
113-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
114-
proxy_set_header Host $http_host;
115-
proxy_redirect off;
116124

117-
if (!-f $request_filename) {
118-
proxy_pass http://app_server_djangoapp;
119-
break;
120-
}
121-
}
122-
}
123-
</pre>
124125
<p>Note that the above code is a simplified version of a production-ready Nginx
125126
configuration. For real SSL and non-SSL templates, take a look at the
126-
<a class="reference external" href="https://github.com/makaimc/underwear/tree/master/underwear/roles/web/templates">Underwear web server templates</a> on GitHub.</p>
127+
<a href="https://github.com/makaimc/underwear/tree/master/underwear/roles/web/templates">Underwear web server templates</a> on GitHub.</p>
127128
<p>WSGI is by design a simple standard interface for running Python code. As
128129
a web developer you won't need to know much more than</p>
129-
<ul class="simple">
130-
<li>what WSGI stands for (Web Server Gateway Inteface)</li>
131-
<li>that a WSGI container is a separate running process that runs on a
132-
different port than your web server</li>
133-
<li>your web server is configured to pass requests to the WSGI container which
134-
runs your web application, then pass the response (in the form of HTML)
135-
back to the requester</li>
130+
<ul>
131+
<li>
132+
<p>what WSGI stands for (Web Server Gateway Inteface)</p>
133+
</li>
134+
<li>
135+
<p>that a WSGI container is a separate running process that runs on a
136+
different port than your web server</p>
137+
</li>
138+
<li>
139+
<p>your web server is configured to pass requests to the WSGI container which
140+
runs your web application, then pass the response (in the form of HTML)
141+
back to the requester</p>
142+
</li>
136143
</ul>
137144
<p>If you're using a standard web framework such as Django, Flask, or
138145
Bottle, or almost any other current Python framework, you don't need to worry
@@ -143,52 +150,46 @@ <h2>WSGI Servers</h2>
143150
<p>However, knowing the WSGI standard and how these frameworks and containers
144151
implement WSGI should be on your learning checklist though as you become
145152
a more experienced Python web developer.</p>
146-
<div class="section" id="wsgi-s-purpose">
147-
<h3>WSGI's Purpose</h3>
153+
<h2>WSGI's Purpose</h2>
148154
<p>Why use WSGI and not just point a web server directly at an application?</p>
149155
<ul>
150-
<li><p class="first"><strong>WSGI gives you flexibility</strong>. Application developers can swap out
151-
web stack components for others. For example, a developer can switch from
152-
Green Unicorn to uWSGI without modifying the application or framework
153-
that implements WSGI.
154-
From <a class="reference external" href="http://www.python.org/dev/peps/pep-3333/">PEP 3333</a>:</p>
155-
<blockquote>
156-
<p>The availability and widespread use of such an API in web servers for
157-
Python [...] would separate choice of framework from choice of web
158-
server, freeing users to choose a pairing that suits them, while
159-
freeing framework and server developers to focus on their preferred
156+
<li>
157+
<p><strong>WSGI gives you flexibility</strong>. Application developers can swap out
158+
web stack components for others. For example, a developer can switch from
159+
Green Unicorn to uWSGI without modifying the application or framework
160+
that implements WSGI.
161+
From <a href="http://www.python.org/dev/peps/pep-3333/">PEP 3333</a>:</p>
162+
<p>The availability and widespread use of such an API in web servers for
163+
Python [...] would separate choice of framework from choice of web
164+
server, freeing users to choose a pairing that suits them, while
165+
freeing framework and server developers to focus on their preferred
160166
area of specialization.</p>
161-
</blockquote>
162167
</li>
163-
<li><p class="first"><strong>WSGI servers promote scaling</strong>. Serving thousands of requests for dynamic
164-
content at once is the domain of WSGI servers, not frameworks.
165-
WSGI servers handle processing requests from the web server and deciding
166-
how to communicate those requests to an application framework's process.
167-
The segregation of responsibilities is important for efficiently scaling
168-
web traffic.</p>
168+
<li>
169+
<p><strong>WSGI servers promote scaling</strong>. Serving thousands of requests for dynamic
170+
content at once is the domain of WSGI servers, not frameworks.
171+
WSGI servers handle processing requests from the web server and deciding
172+
how to communicate those requests to an application framework's process.
173+
The segregation of responsibilities is important for efficiently scaling
174+
web traffic.</p>
169175
</li>
170176
</ul>
171-
</div>
172-
<div class="section" id="wsgi-resources">
173-
<h3>WSGI Resources</h3>
174-
<p><a class="reference external" href="http://www.python.org/dev/peps/pep-0333/">PEP 0333 WSGI v1.0</a>
177+
<h2>WSGI Resources</h2>
178+
<p><a href="http://www.python.org/dev/peps/pep-0333/">PEP 0333 WSGI v1.0</a>
175179
and
176-
<a class="reference external" href="http://www.python.org/dev/peps/pep-3333/">PEP 3333 WSGI v1.0.1</a>
180+
<a href="http://www.python.org/dev/peps/pep-3333/">PEP 3333 WSGI v1.0.1</a>
177181
specifications.</p>
178-
<p><a class="reference external" href="http://gunicorn.org/">Green Unicorn</a>,
179-
<a class="reference external" href="http://code.google.com/p/modwsgi/">mod_wsgi</a>,
180-
<a class="reference external" href="https://github.com/unbit/uwsgi-docs">uWSGI</a>, and
181-
<a class="reference external" href="http://www.gevent.org/">gevent</a> are common WSGI server implementations.</p>
182-
<p>This <a class="reference external" href="http://agiliq.com/blog/2013/07/basics-wsgi/">Basics of WSGI</a> post
182+
<p><a href="http://gunicorn.org/">Green Unicorn</a>,
183+
<a href="http://code.google.com/p/modwsgi/">mod_wsgi</a>,
184+
<a href="https://github.com/unbit/uwsgi-docs">uWSGI</a>, and
185+
<a href="http://www.gevent.org/">gevent</a> are common WSGI server implementations.</p>
186+
<p>This <a href="http://agiliq.com/blog/2013/07/basics-wsgi/">Basics of WSGI</a> post
183187
contains a simple example of how a WSGI-compatible application works.</p>
184-
<p><a class="reference external" href="http://www.apreche.net/complete-single-server-django-stack-tutorial/">Complete single server Django stack tutorial</a> is thorough and informative for
185-
non-paas hosting choices.</p>
188+
<p>This <a href="http://www.apreche.net/complete-single-server-django-stack-tutorial/&gt;">complete single server Django stack tutorial</a>
189+
is thorough and informative for LAMP-stack hosting choices.</p>
186190
<p>This detailed post entitled
187-
<a class="reference external" href="http://bartek.im/blog/2012/07/08/simplicity-nginx-uwsgi-deployment.html">The Beautiful Simplicity of an nginx and uWSGI Deployments</a>
191+
<a href="http://bartek.im/blog/2012/07/08/simplicity-nginx-uwsgi-deployment.html">The Beautiful Simplicity of an nginx and uWSGI Deployments</a>
188192
is great reading for understanding Nginx and uWSGI configurations.</p>
189-
</div>
190-
</div>
191-
192193
<br/>
193194
Next read the
194195
<a href="/web-frameworks.html">web frameworks</a> section.

0 commit comments

Comments
 (0)