Sophie

Sophie

distrib > Fedora > 14 > i386 > media > os > by-pkgid > 5c4f8358fd6fdc210fb0d926bd25802c > files > 244

python-werkzeug-doc-0.6.2-2.fc14.noarch.rpm


<!DOCTYPE HTML>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Werkzeug Documentation</title>
    <link rel="stylesheet" href="../_static/style.css" type="text/css">
    <link rel="stylesheet" href="../_static/print.css" type="text/css" media="print">
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css">
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:   '../',
        VERSION:    '0.6.1'
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/interface.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/werkzeug.js"></script>
    <link rel="contents" title="Global table of contents" href="../contents.html">
    <link rel="index" title="Global index" href="../genindex.html">
    <link rel="search" title="Search" href="../search.html">
    <link rel="top" title="Werkzeug v0.6.1 documentation" href="../index.html">
    <link rel="up" title="Application Deployment" href="index.html">
    <link rel="next" title="Contributed Modules" href="../contrib/index.html">
    <link rel="prev" title="FastCGI" href="fastcgi.html">
    
  </head>
  <body>
    <div class="page">
      <div class="header">
        <h1 class="heading"><a href="../index.html"
          title="back to the documentation overview"><span>Werkzeug</span></a></h1>
      </div>
      <ul class="navigation">
        <li class="indexlink"><a href="../index.html">Overview</a></li>
        <li><a href="fastcgi.html">&laquo; FastCGI</a></li>
        <li class="active"><a href="#">HTTP Proxying</a></li>
        <li><a href="../contrib/index.html">Contributed Modules &raquo;</a></li>
      </ul>
      <div class="body">
        <div id="toc">
          <h3>Table Of Contents</h3>
          <div class="inner"><ul>
<li><a class="reference external" href="#">HTTP Proxying</a><ul>
<li><a class="reference external" href="#creating-a-py-server">Creating a <cite>.py</cite> server</a></li>
<li><a class="reference external" href="#configuring-nginx">Configuring nginx</a></li>
</ul>
</li>
</ul>
</div>
        </div>
        
  <div class="section" id="http-proxying">
<h1>HTTP Proxying<a class="headerlink" href="#http-proxying" title="Permalink to this headline">¶</a></h1>
<p>Many people prefer using a standalone Python HTTP server and proxying that
server via nginx, Apache etc.</p>
<p>A very stable Python server is CherryPy.  This part of the documentation
shows you how to combine your WSGI application with the CherryPy WSGI
server and how to configure the webserver for proxying.</p>
<div class="section" id="creating-a-py-server">
<h2>Creating a <cite>.py</cite> server<a class="headerlink" href="#creating-a-py-server" title="Permalink to this headline">¶</a></h2>
<p>To run your application you need a <cite>start-server.py</cite> file that starts up
the WSGI Server.</p>
<p>It looks something along these lines:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">cherrypy</span> <span class="kn">import</span> <span class="n">wsgiserver</span>
<span class="kn">from</span> <span class="nn">yourapplication</span> <span class="kn">import</span> <span class="n">make_app</span>
<span class="n">server</span> <span class="o">=</span> <span class="n">wsgiserver</span><span class="o">.</span><span class="n">CherryPyWSGIServer</span><span class="p">((</span><span class="s">&#39;localhost&#39;</span><span class="p">,</span> <span class="mi">8080</span><span class="p">),</span> <span class="n">make_app</span><span class="p">())</span>
<span class="k">try</span><span class="p">:</span>
    <span class="n">server</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
<span class="k">except</span> <span class="ne">KeyboardInterrupt</span><span class="p">:</span>
    <span class="n">server</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
</pre></div>
</div>
<p>If you now start the file the server will listen on <cite>localhost:8080</cite>.  Keep
in mind that WSGI applications behave slightly different for proxied setups.
If you have not developed your application for proxying in mind, you can
apply the <a title="werkzeug.contrib.fixers.ProxyFix" class="reference external" href="../contrib/fixers.html#werkzeug.contrib.fixers.ProxyFix"><tt class="xref py py-class docutils literal"><span class="pre">ProxyFix</span></tt></a> middleware.</p>
</div>
<div class="section" id="configuring-nginx">
<h2>Configuring nginx<a class="headerlink" href="#configuring-nginx" title="Permalink to this headline">¶</a></h2>
<p>As an example we show here how to configure nginx to proxy to the server.</p>
<p>The basic nginx configuration looks like this:</p>
<div class="highlight-python"><pre>location / {
    proxy_set_header        Host $host;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass              http://127.0.0.1:8080;
    proxy_redirect          default;
}</pre>
</div>
<p>Since Nginx doesn&#8217;t start your server for you, you have to do it by yourself.  You
can either write an <cite>init.d</cite> script for that or execute it inside a screen
session:</p>
<div class="highlight-python"><pre>$ screen
$ python start-server.py</pre>
</div>
</div>
</div>


        <div style="clear: both"></div>
      </div>
      <div class="footer">
        © Copyright 2008 by the <a href="http://pocoo.org/">Pocoo Team</a>,
        documentation generated by <a href="http://sphinx.pocoo.org/">Sphinx</a>
      </div>
    </div>
  </body>
</html>