2012-05-07 17:08:58 +04:00
|
|
|
|
|
|
|
|
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
|
|
|
|
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
|
2012-05-18 16:29:52 +04:00
|
|
|
<title>Nginx setup — 0bin 0.1 documentation</title>
|
2012-05-07 17:08:58 +04:00
|
|
|
|
|
|
|
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
|
|
|
|
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
var DOCUMENTATION_OPTIONS = {
|
|
|
|
URL_ROOT: '../',
|
|
|
|
VERSION: '0.1',
|
|
|
|
COLLAPSE_INDEX: false,
|
|
|
|
FILE_SUFFIX: '.html',
|
|
|
|
HAS_SOURCE: true
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript" src="../_static/jquery.js"></script>
|
|
|
|
<script type="text/javascript" src="../_static/underscore.js"></script>
|
|
|
|
<script type="text/javascript" src="../_static/doctools.js"></script>
|
|
|
|
<link rel="top" title="0bin 0.1 documentation" href="../index.html" />
|
|
|
|
<link rel="next" title="Using supervisor" href="using_supervisor.html" />
|
2012-05-18 16:29:52 +04:00
|
|
|
<link rel="prev" title="Apache setup" href="apache_install.html" />
|
2012-05-07 17:08:58 +04:00
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div class="related">
|
|
|
|
<h3>Navigation</h3>
|
|
|
|
<ul>
|
|
|
|
<li class="right" style="margin-right: 10px">
|
|
|
|
<a href="../genindex.html" title="General Index"
|
|
|
|
accesskey="I">index</a></li>
|
|
|
|
<li class="right" >
|
|
|
|
<a href="using_supervisor.html" title="Using supervisor"
|
|
|
|
accesskey="N">next</a> |</li>
|
|
|
|
<li class="right" >
|
2012-05-18 16:29:52 +04:00
|
|
|
<a href="apache_install.html" title="Apache setup"
|
2012-05-07 17:08:58 +04:00
|
|
|
accesskey="P">previous</a> |</li>
|
|
|
|
<li><a href="../index.html">0bin 0.1 documentation</a> »</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="document">
|
|
|
|
<div class="documentwrapper">
|
|
|
|
<div class="bodywrapper">
|
|
|
|
<div class="body">
|
|
|
|
|
2012-05-18 16:29:52 +04:00
|
|
|
<div class="section" id="nginx-setup">
|
|
|
|
<h1>Nginx setup<a class="headerlink" href="#nginx-setup" title="Permalink to this headline">¶</a></h1>
|
|
|
|
<p>Nginx is a very popular choice to serve a Python project:</p>
|
|
|
|
<ul class="simple">
|
|
|
|
<li>It’s fast.</li>
|
|
|
|
<li>It’s lightweight.</li>
|
|
|
|
<li>Configuration files are simple.</li>
|
|
|
|
</ul>
|
|
|
|
<p>If you have your own server, it’s the best choice. If not, try the easiest
|
|
|
|
setup, or the Apache setup.</p>
|
|
|
|
<p>Nginx doesn’t run any Python process, it only serve requests from outside to
|
|
|
|
the Python server.</p>
|
|
|
|
<p>Therefor there are two steps:</p>
|
|
|
|
<ul class="simple">
|
|
|
|
<li>Run the Python process.</li>
|
|
|
|
<li>Run Nginx.</li>
|
|
|
|
</ul>
|
|
|
|
<p>You will benefit from having:</p>
|
|
|
|
<ul class="simple">
|
|
|
|
<li>the possiblity to have several projects listening to the port 80;</li>
|
|
|
|
<li>several Apache module at your disposal (like requests throttling);</li>
|
|
|
|
<li>Apache robustness in front end: it’s secure, and there is much less chance
|
|
|
|
it will crash under heavy load;</li>
|
|
|
|
<li>your web site processes won’t run with admin rights, even if –user doesn’t
|
|
|
|
work on your OS;</li>
|
|
|
|
<li>the ability to manage a Python process without touching Nginx or the other
|
|
|
|
processes. It’s very handy for updates.</li>
|
|
|
|
</ul>
|
|
|
|
<div class="section" id="the-python-process">
|
|
|
|
<h2>The Python process<a class="headerlink" href="#the-python-process" title="Permalink to this headline">¶</a></h2>
|
|
|
|
<p>Run 0bin as usual, but this time make it listen to a local port and host. E.G:</p>
|
|
|
|
<div class="highlight-python"><pre>zerobin --host 127.0.0.1 --port 8000</pre>
|
|
|
|
</div>
|
|
|
|
<p>In PHP, when you edit a file, the changes are immediatly visible. In Python,
|
|
|
|
the whole code is often loaded in memory for performance reasons. This means
|
|
|
|
you have to restart the Python process to see the changes effect. Having a
|
|
|
|
separate process let you do this without having to restart the server.</p>
|
|
|
|
</div>
|
|
|
|
<div class="section" id="nginx">
|
|
|
|
<h2>Nginx<a class="headerlink" href="#nginx" title="Permalink to this headline">¶</a></h2>
|
|
|
|
<p>Nginx can be installed with you usual package manager, so we won’t cover
|
|
|
|
installing it.</p>
|
|
|
|
<p>Vous must create a Nginx configuration file for 0bin. On GNU/Linux, they usually
|
|
|
|
go into /etc/nginx/conf.d/. Name it zerobin.conf.</p>
|
2012-05-19 00:18:40 +04:00
|
|
|
<p>The minimal configuration file to run the site is:</p>
|
|
|
|
<div class="highlight-python"><pre>server {
|
|
|
|
listen 80;
|
|
|
|
server_name www.yourwebsite.com;
|
|
|
|
|
|
|
|
location / {
|
|
|
|
proxy_pass http://127.0.0.1:8000;
|
|
|
|
}
|
|
|
|
}</pre>
|
|
|
|
</div>
|
|
|
|
<p><cite>proxy_pass</cite> just passes the external request to the Python process.
|
|
|
|
The port much match the one used by the 0bin process of course.</p>
|
|
|
|
<p>You can make some adjustements to get a better user experience:</p>
|
|
|
|
<div class="highlight-python"><pre>server {
|
|
|
|
listen 80;
|
|
|
|
server_name www.yourwebsite.com;
|
|
|
|
|
|
|
|
location /favicon.ico {
|
|
|
|
root /path/to/zerobin/static/img;
|
|
|
|
}
|
|
|
|
|
|
|
|
location /static/ {
|
|
|
|
root /path/to/zerobin;
|
|
|
|
gzip on;
|
|
|
|
gzip_http_version 1.0;
|
|
|
|
gzip_vary on;
|
|
|
|
gzip_comp_level 6;
|
|
|
|
gzip_proxied any;
|
|
|
|
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
|
|
|
|
gzip_buffers 16 8k;
|
|
|
|
# Disable gzip for certain browsers.
|
|
|
|
gzip_disable ~@~\MSIE [1-6].(?!.*SV1)~@~];
|
|
|
|
expires modified +90d;
|
|
|
|
}
|
|
|
|
|
|
|
|
location / {
|
|
|
|
proxy_pass http://zerobin_cherrypy;
|
|
|
|
}
|
|
|
|
}</pre>
|
|
|
|
</div>
|
|
|
|
<p>This make Nginx serve the favicon and static files, set the expire HTTP headers
|
|
|
|
and make sure gzip compression is used with browsers that support it.</p>
|
2012-05-18 16:29:52 +04:00
|
|
|
</div>
|
2012-05-07 17:08:58 +04:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="sphinxsidebar">
|
|
|
|
<div class="sphinxsidebarwrapper">
|
2012-05-18 16:29:52 +04:00
|
|
|
<h3><a href="../index.html">Table Of Contents</a></h3>
|
|
|
|
<ul>
|
|
|
|
<li><a class="reference internal" href="#">Nginx setup</a><ul>
|
|
|
|
<li><a class="reference internal" href="#the-python-process">The Python process</a></li>
|
|
|
|
<li><a class="reference internal" href="#nginx">Nginx</a></li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
|
2012-05-07 17:08:58 +04:00
|
|
|
<h4>Previous topic</h4>
|
|
|
|
<p class="topless"><a href="apache_install.html"
|
2012-05-18 16:29:52 +04:00
|
|
|
title="previous chapter">Apache setup</a></p>
|
2012-05-07 17:08:58 +04:00
|
|
|
<h4>Next topic</h4>
|
|
|
|
<p class="topless"><a href="using_supervisor.html"
|
|
|
|
title="next chapter">Using supervisor</a></p>
|
|
|
|
<h3>This Page</h3>
|
|
|
|
<ul class="this-page-menu">
|
|
|
|
<li><a href="../_sources/en/nginx_install.txt"
|
|
|
|
rel="nofollow">Show Source</a></li>
|
|
|
|
</ul>
|
|
|
|
<div id="searchbox" style="display: none">
|
|
|
|
<h3>Quick search</h3>
|
|
|
|
<form class="search" action="../search.html" method="get">
|
|
|
|
<input type="text" name="q" />
|
|
|
|
<input type="submit" value="Go" />
|
|
|
|
<input type="hidden" name="check_keywords" value="yes" />
|
|
|
|
<input type="hidden" name="area" value="default" />
|
|
|
|
</form>
|
|
|
|
<p class="searchtip" style="font-size: 90%">
|
|
|
|
Enter search terms or a module, class or function name.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<script type="text/javascript">$('#searchbox').show(0);</script>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="clearer"></div>
|
|
|
|
</div>
|
|
|
|
<div class="related">
|
|
|
|
<h3>Navigation</h3>
|
|
|
|
<ul>
|
|
|
|
<li class="right" style="margin-right: 10px">
|
|
|
|
<a href="../genindex.html" title="General Index"
|
|
|
|
>index</a></li>
|
|
|
|
<li class="right" >
|
|
|
|
<a href="using_supervisor.html" title="Using supervisor"
|
|
|
|
>next</a> |</li>
|
|
|
|
<li class="right" >
|
2012-05-18 16:29:52 +04:00
|
|
|
<a href="apache_install.html" title="Apache setup"
|
2012-05-07 17:08:58 +04:00
|
|
|
>previous</a> |</li>
|
|
|
|
<li><a href="../index.html">0bin 0.1 documentation</a> »</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="footer">
|
|
|
|
© Copyright 2012, Sam et Max.
|
|
|
|
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3.
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|