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
+62-5Lines changed: 62 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -83,11 +83,65 @@ <h1>WSGI Servers</h1>
83
83
<aclass="reference external" href="http://www.python.org/dev/peps/pep-3333/">PEP 3333</a>, which defines the
84
84
v1.0.1 WSGI standard.</p>
85
85
<imgalt="WSGI Server <-> Web server <-> Browser" class="technical-diagram" src="theme/img/web-browser-server-wsgi.png" style="width: 100%;" />
86
-
<p>Requests from the browser that are not for static assets (this is specified
87
-
in the web server's configuration which requests are for static assets and
88
-
which are not) are passed to the WSGI server. Once the request is
89
-
processed and generated by the WSGI server, the response is passed
90
-
back through the web server and onto the browser.</p>
86
+
<p>A web server's configuration specifies what requests should be passed to
87
+
the WSGI server to process. Once a request is processed and generated by the
88
+
WSGI server, the response is passed back through the web server and onto
89
+
the browser. For example, this Nginx web server's configuration specifics
90
+
Nginx should handle static assets (such as images, JavaScript, and CSS
91
+
files) under the /static directory and pass all other requests to the WSGI
92
+
server running on port 8000:</p>
93
+
<preclass="literal-block">
94
+
# this specifies that there is a WSGI server running on port 8000
95
+
upstream app_server_djangoapp {
96
+
server localhost:8000 fail_timeout=0;
97
+
}
98
+
99
+
# Nginx is set up to run on the standard HTTP port and listen for requests
100
+
server {
101
+
listen 80;
102
+
103
+
# nginx should serve up static files and never send to the WSGI server
104
+
location /static {
105
+
autoindex on;
106
+
alias /srv/www/assets;
107
+
}
108
+
109
+
# requests that do not fall under /static are passed on to the WSGI
110
+
# server that was specified above running on port 8000
<p>Note that the above code is a simplified version of a production-ready Nginx
124
+
configuration. For real SSL and non-SSL templates, take a look at the
125
+
<aclass="reference external" href="https://github.com/makaimc/underwear/tree/master/underwear/roles/web/templates">Underwear web server templates</a> on GitHub.</p>
126
+
<p>WSGI is by design a simple standard interface for running Python code. As
127
+
a web developer you won't need to know much more than</p>
128
+
<ulclass="simple">
129
+
<li>what WSGI stands for (Web Server Gateway Inteface)</li>
130
+
<li>that a WSGI container is a separate running process that runs on a
131
+
different port than your web server</li>
132
+
<li>your web server is configured to pass requests to the WSGI container which
133
+
runs your web application, then pass the response (in the form of HTML)
134
+
back to the requester</li>
135
+
</ul>
136
+
<p>If you're using a standard web framework such as Django, Flask, or
137
+
Bottle, or almost any other current Python framework, you don't need to worry
138
+
about how frameworks implement the application side of the WSGI standard.
139
+
Likewise, if you're using a standard WSGI container such as Green Unicorn,
140
+
uWSGI, mod_wsgi, or gevent, you can get them running without worrying about
141
+
how they implement the WSGI standard.</p>
142
+
<p>However, knowing the WSGI standard and how these frameworks and containers
143
+
implement WSGI should be on your learning checklist though as you become
contains a simple example of how a WSGI-compatible application works.</p>
103
157
<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
104
158
non-paas hosting choices.</p>
159
+
<p>This detailed post entitled
160
+
<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>
161
+
is great reading for understanding Nginx and uWSGI configurations.</p>
0 commit comments