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
<a href="https://www.python.org/dev/peps/pep-3333/">PEP3333 WSGI server standard specification</a>
so that it can run Python web applications that implement the application
interface. For example, if you write a web application with a
<a href="/web-frameworks.html">web framework</a> such as <a href="/django.html">Django</a>,
<a href="/flask.html">Flask</a> or <a href="/bottle.html">Bottle</a>, then your application
implements the WSGI specification. </p>
<div class="well see-also">Gunicorn is an implementation of the <a href="/wsgi-servers.html">WSGI servers</a> concept. Learn how these pieces fit together in the <a href="/deployment.html">deployment</a> chapter or view the <a href="/table-of-contents.html">table of contents</a> for all topics.</div>
<h2>How does Gunicorn know how to run my web app?</h2>
<p>Gunicorn knows how to run a web application based on the hook between the
WSGI server and the WSGI-compliant web app.</p>
<p>Here is an example of a typical Django web application and how it is run
as an example Django project. Within the <a href="https://github.com/makaimc/compare-python-web-frameworks/tree/master/django_defaults/django_defaults">django_defaults</a>
project subdirectory, there is a short <a href="https://github.com/makaimc/compare-python-web-frameworks/blob/master/django_defaults/django_defaults/wsgi.py">wsgi.py</a>
<p>That <code>wsgi.py</code> file was generated by the <code>django-admin.py startproject</code> command
when the Django project was first created. Django exposes an <code>application</code>
variable via that <code>wsgi.py</code> file so that a WSGI server can use <code>application</code>
as a hook for running the web app. Here's how the situation looks visually:</p>
<p><img src="/img/gunicorn-django-wsgi.png" alt="Gunicorn WSGI server invoking a Django WSGI application." width="100%" class="technical-diagram" /></p>
<h2>What's a "pre-fork" worker model?</h2>
<p>Gunicorn is based on a pre-fork worker model, compared to a worker model
architecture. The pre-work worker model means that a master thread spins up
workers to handle requests but otherwise does not control how those workers
perform the request handling. Each worker is independent of the controller.</p>
<h3>Gunicorn resources</h3>
<ul>
<li>
<p>There are three framework-specific posts on the
<a href="/blog.html">Full Stack Python blog</a> for configuring Gunicorn for
development on Ubuntu: </p>
<ol>
<li><a href="/blog/python-3-django-gunicorn-ubuntu-1604-xenial-xerus.html">Setting up Python 3, Django and Gunicorn on Ubuntu 16.04 LTS</a></li>
<li><a href="/blog/python-3-flask-green-unicorn-ubuntu-1604-xenial-xerus.html">How to set up Python 3, Flask and Green Unicorn on Ubuntu 16.04 LTS</a></li>
<li><a href="/blog/python-3-bottle-gunicorn-ubuntu-1604-xenial-xerus.html">Configuring Python 3, Bottle and Gunicorn for Development on Ubuntu 16.04 LTS</a></li>
</ol>
</li>
<li>
<p><a href="https://vxlabs.com/2015/12/08/gunicorn-as-your-django-development-server/">gunicorn as your Django development server</a>
is a short post with a few good tips on using Gunicorn for local
application development.</p>
</li>
<li>
<p>The <a href="http://www.deploypython.com/">Full Stack Python Guide to Deployments</a>
provides detailed step-by-step instructions for deploying Gunicorn as part
of an entire Python web application deployment.</p>
</li>
<li>
<p><a href="http://prakhar.me/articles/flask-on-nginx-and-gunicorn/">Flask on Nginx and Gunicorn</a>
combines the <a href="/nginx.html">Nginx web server</a> with Gunicorn in a deployment
to serve up a Flask application.</p>
</li>
<li>
<p>The answers to the question "<a href="http://stackoverflow.com/questions/16857955/running-django-with-gunicorn-best-practice">what's the best practice for running Django with Gunicorn?</a>"
provide some nuance for how Gunicorn should be invokin the callable
application variable provided by Django within a deployment.</p>
</li>
<li>
<p><a href="http://linoxide.com/linux-how-to/install-django-gunicorn-nginx-freebsd-10-2/">How to Install Django with Gunicorn and Nginx on FreeBSD 10.2</a>
is a tutorial for FreeBSD, which is not often used in walkthroughs compared
to the frequency that Ubuntu and CentOS tutorials appear.</p>
</li>
<li>
<p><a href="http://www.philchen.com/2015/08/08/how-to-make-a-scalable-python-web-app-using-flask-and-gunicorn-nginx-on-ubuntu-14-04">How to make a Scalable Python Web App using Flask, Gunicorn, NGINX on Ubuntu 14.04</a>
and
<a href="https://github.com/defshine/flaskblog/wiki/Deploy-Flask-App-on-Ubuntu(Virtualenv-Gunicorn-Nginx-Supervisor)">Deploy a Flask App on Ubuntu</a>
both provide steps for setting up a Flask web app using Gunicorn. There
isn't much explanation provided with each tutorial but they can still be
good concise references in case you're having issues with Ubuntu.</p>
<a href="http://www.deploypython.com/"><img src="/img/sponsored/fsp-deployment-guide.png" alt="The Full Stack Python Guide to Deployments" width="100%"></a>
<p style="font-size: .8em; margin-top: 10px;">Searching for a complete, step-by-step deployment walkthrough? Learn more about <a href="http://www.deploypython.com/">The Full Stack Python Guide to Deployments book</a>.
<div style="padding: 0 0 20px 0; margin: 0 0 20px 0; background-color: #22B24C;">
<div class="container">
<p class="banner"><a href="https://www.gumroad.com/l/python-deployments" style="color: #fff">Learning web development? Check out The Full Stack Python Guide to Deployments book</a>!</p>