<metaname="description" content="A web server handles HTTP requests and responses. Learn how web servers work with Python web apps on Full Stack Python.">
<divstyle="padding: 0 0 20px 0; margin: 0 0 20px 0; background-color: #22B24C;">
<divclass="container">
<h2style="color: #fff; margin: 20px 40px 0 0;"><ahref="https://www.gumroad.com/l/python-deployments" style="color: #fff">The Full Stack Python Guide to Deployments book</a> has been released!</h2>
</div>
</div><ahref="https://github.com/makaimc/fullstackpython.com"><imgstyle="position: absolute; top: 0; right: 0; border: 0;" src="/theme/img/fork.png" alt="Fork me on GitHub"></a>
and commonly a content response. Some status codes, such as 204 (No content)
and 403 (Forbidden), do not have content responses.</p>
<p>In a simple case, the client will request a static asset such as a picture
or JavaScript file. The file sits on the file system in a location the
web server is authorized to access and the web server sends the file
to the client with a 200 status code. If the client already requested the
file and the file has not changed, the web server will pass back a 304
"Not modified" response indicating the client already has the latest version
of that file.</p>
<p><imgsrc="theme/img/web-browser-server-requests.png" width="100%" class="technical-diagram" alt="Web server and web browser request-response cycle" /></p>
<p>A web server sends files to a web browser based on the web browser's
request. In the first request, the browser accessed the
"www.fullstackpython.com"
address and the server responded with the index.html HTML-formatted file.
That HTML file contained references to other files, such as style.css and
script.js that the browser then requested from the server.</p>
<p>Sending static assets (such as CSS and JavaScript files) can eat up a
large amount of bandwidth which is why using a Content Delivery Network
(CDN) is important when possible (see the content delivery network
<p><ahref="http://arstechnica.com/gadgets/2012/11/how-to-set-up-a-safe-and-secure-web-server/">How to set up a safe and secure Web server</a></p>
</li>
<li>
<p><ahref="http://library.linode.com/web-servers/apache/mod-wsgi/ubuntu-10.04-lucid">Apache and mod_wsgi on Ubuntu 10.04</a></p>
</li>
<li>
<p>A reference with the full list of
<ahref="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">HTTP status codes</a>
is provided by W3C.</p>
</li>
<li>
<p><ahref="http://ibuildings.nl/blog/2013/03/4-http-security-headers-you-should-always-be-using">4 HTTP Security Headers You Should Always Be Using</a></p>
</li>
<li>
<p>If you're looking to learn about web servers by building one, here's
<ahref="http://ruslanspivak.com/lsbaws-part2/">part two</a> and <ahref="http://ruslanspivak.com/lsbaws-part3/">part three</a>
of a great tutorial that shows how to code a web server in Python.</p>
</li>
</ul>
<h2>Nginx resources</h2>
<ul>
<li>
<p><ahref="http://nginx.com/blog/inside-nginx-how-we-designed-for-performance-scale/">Inside Nginx: How we designed for performance and scale</a>
is a blog post from the developers behind Nginx on why they believe their
architecture model is more performant and scalable than other approaches
used to build web servers.</p>
</li>
<li>
<p><ahref="http://articles.slicehost.com/nginx">Nginx web server tutorials</a> are oldies
but goodies on setting up previous versions of Nginx. </p>
</li>
<li>
<p><ahref="http://carrot.is/coding/nginx_introduction">Nginx for Developers: An Introduction</a></p>
</li>
<li>
<p>An example of an <ahref="http://tautt.com/best-nginx-configuration-for-security/">Nginx security configuration</a>.</p>
</li>
<li>
<p><ahref="http://arstechnica.com/business/2011/11/a-faster-web-server-ripping-out-apache-for-nginx/">A faster Web server: ripping out Apache for Nginx</a>
explains how Nginx can be used instead of Apache in some cases for
better performance.</p>
</li>
<li>
<p><ahref="https://2ton.com.au/rwasa/">rwasa</a> is a newly released web server written
in Assembly with no external dependencies that tuned to be faster than Nginx.
The benchmarks are worth taking a look at to see if this server could fit
your needs if you need the fastest performance trading off for as of yet
untested web server.</p>
</li>
<li>
<p><ahref="http://lincolnloop.com/blog/rate-limiting-nginx/">Rate Limiting with Nginx</a>
covers how to mitigate against brute force password guessing attempts using
Nginx rate limits.</p>
</li>
<li>
<p><ahref="http://tenzer.dk/nginx-with-dynamic-upstreams/">Nginx with dynamic upstreams</a>
is an important note for setting up your upstream WSGI server(s) if you're
using Nginx as a reverse proxy with hostnames that change.</p>
</li>
</ul>
<h2>Web servers learning checklist</h2>
<ol>
<li>
<p>Choose a web server. <ahref="http://nginx.org/en/">Nginx</a> is often recommended
although <ahref="http://httpd.apache.org/">Apache</a> is also a great choice.</p>
</li>
<li>
<p>Create an SSL certificate. For testing use a self-signed certificate
and for a production app buy one from <ahref="http://www.digicert.com/">Digicert</a>.
Configure the web server to serve traffic over SSL. You'll need SSL for
serving only HTTPS traffic and preventing security issues that occur with
unencrypted user input.</p>
</li>
<li>
<p>Configure the web server to serve up static files such as CSS, JavaScript
and images.</p>
</li>
<li>
<p>Once you set up the <ahref="/wsgi-servers.html">WSGI server</a> you'll need to
configure the web server as a pass through for dynamic content.</p>
</li>
</ol>
<h3>What do you want to learn after the web server is configured?</h3>
<ahref="http://www.deploypython.com/"><imgsrc="//static.fullstackpython.com/fsp-deployment-guide.png" alt="The Full Stack Python Guide to Deployments" width="100%"></a>
<pstyle="font-size: .8em; margin-top: 10px;">Searching for a complete, step-by-step deployment walkthrough? Learn more about <ahref="http://www.deploypython.com/">The Full Stack Python Guide to Deployments book</a>.
</p>
</div>
</div><divclass="panel panel-success">
<divclass="panel-heading">
<h3class="panel-head"><ahref="/table-of-contents.html" style="color: #fff;">Table of Contents</a></h3>
<ahref="/about-author.html" class="list-group-item smaller-item " style='font-family: "Helvetica Neue",sans-serif;'>About the Author</a>
</div>
</div>
<divclass="panel panel-success">
<divclass="panel-body">
<ahref="http://www.deploypython.com/"><imgsrc="//static.fullstackpython.com/fsp-deployment-guide.png" alt="The Full Stack Python Guide to Deployments" width="100%"></a>
<pstyle="font-size: .8em; margin-top: 10px;">Searching for a complete, step-by-step deployment walkthrough? Learn more about <ahref="http://www.deploypython.com/">The Full Stack Python Guide to Deployments book</a>.