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: wsgi-servers.html
+77-76Lines changed: 77 additions & 76 deletions
Original file line number
Diff line number
Diff line change
@@ -74,65 +74,72 @@
74
74
</div>
75
75
<divclass="row">
76
76
<divclass="col-md-8">
77
-
<divclass="section" id="id1">
78
-
<h2>WSGI Servers</h2>
79
-
<p>A <aclass="reference external" href="http://wsgi.readthedocs.org/en/latest/">Web Server Gateway Interface</a>
77
+
<h1>WSGI Servers</h1>
78
+
<p>A <ahref="http://wsgi.readthedocs.org/en/latest/">Web Server Gateway Interface</a>
80
79
(WSGI) server implements the web server side of the WSGI interface for
81
80
running Python web applications. The WSGI standard v1.0 is specified in
82
-
<aclass="reference external" href="http://www.python.org/dev/peps/pep-0333/">PEP 0333</a>. As of September 2010,
81
+
<ahref="http://www.python.org/dev/peps/pep-0333/">PEP 0333</a>. As of September 2010,
83
82
WSGI v1.0 is superseded by
84
-
<aclass="reference external" href="http://www.python.org/dev/peps/pep-3333/">PEP 3333</a>, which defines the
83
+
<ahref="http://www.python.org/dev/peps/pep-3333/">PEP 3333</a>, which defines the
85
84
v1.0.1 WSGI standard.</p>
86
-
<imgalt="WSGI Server <-> Web server <-> Browser" class="technical-diagram" src="theme/img/web-browser-server-wsgi.png" style="width: 100%;" />
85
+
<p><imgsrc="theme/img/web-browser-server-wsgi.png" alt="WSGI Server <-> Web server <-> Browser" width="100%" class="technical-diagram" /></p>
87
86
<p>A web server's configuration specifies what requests should be passed to
88
87
the WSGI server to process. Once a request is processed and generated by the
89
88
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
91
91
Nginx should handle static assets (such as images, JavaScript, and CSS
92
92
files) under the /static directory and pass all other requests to the WSGI
93
93
server running on port 8000:</p>
94
-
<preclass="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
+
<divclass="codehilite"><pre><spanclass="c"># this specifies that there is a WSGI server running on port 8000</span>
<p>Note that the above code is a simplified version of a production-ready Nginx
125
126
configuration. For real SSL and non-SSL templates, take a look at the
126
-
<aclass="reference external" href="https://github.com/makaimc/underwear/tree/master/underwear/roles/web/templates">Underwear web server templates</a> on GitHub.</p>
127
+
<ahref="https://github.com/makaimc/underwear/tree/master/underwear/roles/web/templates">Underwear web server templates</a> on GitHub.</p>
127
128
<p>WSGI is by design a simple standard interface for running Python code. As
128
129
a web developer you won't need to know much more than</p>
129
-
<ulclass="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>
136
143
</ul>
137
144
<p>If you're using a standard web framework such as Django, Flask, or
138
145
Bottle, or almost any other current Python framework, you don't need to worry
@@ -143,52 +150,46 @@ <h2>WSGI Servers</h2>
143
150
<p>However, knowing the WSGI standard and how these frameworks and containers
144
151
implement WSGI should be on your learning checklist though as you become
145
152
a more experienced Python web developer.</p>
146
-
<divclass="section" id="wsgi-s-purpose">
147
-
<h3>WSGI's Purpose</h3>
153
+
<h2>WSGI's Purpose</h2>
148
154
<p>Why use WSGI and not just point a web server directly at an application?</p>
149
155
<ul>
150
-
<li><pclass="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 <aclass="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 <ahref="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
160
166
area of specialization.</p>
161
-
</blockquote>
162
167
</li>
163
-
<li><pclass="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
<ahref="https://github.com/unbit/uwsgi-docs">uWSGI</a>, and
185
+
<ahref="http://www.gevent.org/">gevent</a> are common WSGI server implementations.</p>
186
+
<p>This <ahref="http://agiliq.com/blog/2013/07/basics-wsgi/">Basics of WSGI</a> post
183
187
contains a simple example of how a WSGI-compatible application works.</p>
184
-
<p><aclass="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 <ahref="http://www.apreche.net/complete-single-server-django-stack-tutorial/>">complete single server Django stack tutorial</a>
189
+
is thorough and informative for LAMP-stack hosting choices.</p>
186
190
<p>This detailed post entitled
187
-
<aclass="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
+
<ahref="http://bartek.im/blog/2012/07/08/simplicity-nginx-uwsgi-deployment.html">The Beautiful Simplicity of an nginx and uWSGI Deployments</a>
188
192
is great reading for understanding Nginx and uWSGI configurations.</p>
0 commit comments