This file is indexed.

/usr/share/doc/python-werkzeug-doc/html/deployment/fastcgi.html is in python-werkzeug-doc 0.10.4+dfsg1-1ubuntu1.1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<!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" />
    
    <title>FastCGI &mdash; Werkzeug 0.10.4 documentation</title>
    
    <link rel="stylesheet" href="../_static/werkzeug.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.10.4',
        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="Werkzeug 0.10.4 documentation" href="../index.html" />
    <link rel="up" title="Application Deployment" href="index.html" />
    <link rel="next" title="HTTP Proxying" href="proxying.html" />
    <link rel="prev" title="mod_wsgi (Apache)" href="mod_wsgi.html" /> 
  </head>
  <body role="document">
    <div class="related" role="navigation" aria-label="related navigation">
      <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="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="proxying.html" title="HTTP Proxying"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="mod_wsgi.html" title="mod_wsgi (Apache)"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../index.html">Werkzeug 0.10.4 documentation</a> &raquo;</li>
          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Application Deployment</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="fastcgi">
<h1>FastCGI<a class="headerlink" href="#fastcgi" title="Permalink to this headline"></a></h1>
<p>A very popular deployment setup on servers like <a class="reference external" href="http://www.lighttpd.net/">lighttpd</a> and <a class="reference external" href="http://nginx.net/">nginx</a>
is FastCGI.  To use your WSGI application with any of them you will need
a FastCGI server first.</p>
<p>The most popular one is <a class="reference external" href="http://trac.saddi.com/flup">flup</a> which we will use for this guide.  Make
sure to have it installed.</p>
<div class="section" id="creating-a-fcgi-file">
<h2>Creating a <cite>.fcgi</cite> file<a class="headerlink" href="#creating-a-fcgi-file" title="Permalink to this headline"></a></h2>
<p>First you need to create the FastCGI server file.  Let&#8217;s call it
<cite>yourapplication.fcgi</cite>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="ch">#!/usr/bin/python</span>
<span class="kn">from</span> <span class="nn">flup.server.fcgi</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="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s1">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">application</span> <span class="o">=</span> <span class="n">make_app</span><span class="p">()</span>
    <span class="n">WSGIServer</span><span class="p">(</span><span class="n">application</span><span class="p">)</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
</pre></div>
</div>
<p>This is enough for Apache to work, however ngingx and older versions of
lighttpd need a socket to be explicitly passed to communicate with the FastCGI
server.  For that to work you need to pass the path to the socket to the
<code class="xref py py-class docutils literal"><span class="pre">WSGIServer</span></code>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">WSGIServer</span><span class="p">(</span><span class="n">application</span><span class="p">,</span> <span class="n">bindAddress</span><span class="o">=</span><span class="s1">&#39;/path/to/fcgi.sock&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">run</span><span class="p">()</span>
</pre></div>
</div>
<p>The path has to be the exact same path you define in the server
config.</p>
<p>Save the <cite>yourapplication.fcgi</cite> file somewhere you will find it again.
It makes sense to have that in <cite>/var/www/yourapplication</cite> or something
similar.</p>
<p>Make sure to set the executable bit on that file so that the servers
can execute it:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c1"># chmod +x /var/www/yourapplication/yourapplication.fcgi</span>
</pre></div>
</div>
</div>
<div class="section" id="configuring-lighttpd">
<h2>Configuring lighttpd<a class="headerlink" href="#configuring-lighttpd" title="Permalink to this headline"></a></h2>
<p>A basic FastCGI configuration for lighttpd looks like this:</p>
<div class="highlight-python"><div class="highlight"><pre>fastcgi.server = (&quot;/yourapplication.fcgi&quot; =&gt;
    ((
        &quot;socket&quot; =&gt; &quot;/tmp/yourapplication-fcgi.sock&quot;,
        &quot;bin-path&quot; =&gt; &quot;/var/www/yourapplication/yourapplication.fcgi&quot;,
        &quot;check-local&quot; =&gt; &quot;disable&quot;,
        &quot;max-procs&quot; -&gt; 1
    ))
)

alias.url = (
    &quot;/static/&quot; =&gt; &quot;/path/to/your/static&quot;
)

url.rewrite-once = (
    &quot;^(/static.*)$&quot; =&gt; &quot;$1&quot;,
    &quot;^(/.*)$&quot; =&gt; &quot;/yourapplication.fcgi$1&quot;
</pre></div>
</div>
<p>Remember to enable the FastCGI, alias and rewrite modules. This configuration
binds the application to <cite>/yourapplication</cite>.  If you want the application to
work in the URL root you have to work around a lighttpd bug with the
<code class="xref py py-class docutils literal"><span class="pre">LighttpdCGIRootFix</span></code> middleware.</p>
<p>Make sure to apply it only if you are mounting the application the URL
root. Also, see the Lighty docs for more information on <a class="reference external" href="http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModFastCGI">FastCGI and Python</a> (note that
explicitly passing a socket to run() is no longer necessary).</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>Installing FastCGI applications on nginx is a bit tricky because by default
some FastCGI parameters are not properly forwarded.</p>
<p>A basic FastCGI configuration for nginx looks like this:</p>
<div class="highlight-python"><div class="highlight"><pre>location /yourapplication/ {
    include fastcgi_params;
    if ($uri ~ ^/yourapplication/(.*)?) {
        set $path_url $1;
    }
    fastcgi_param PATH_INFO $path_url;
    fastcgi_param SCRIPT_NAME /yourapplication;
    fastcgi_pass unix:/tmp/yourapplication-fcgi.sock;
}
</pre></div>
</div>
<p>This configuration binds the application to <cite>/yourapplication</cite>.  If you want
to have it in the URL root it&#8217;s a bit easier because you don&#8217;t have to figure
out how to calculate <cite>PATH_INFO</cite> and <cite>SCRIPT_NAME</cite>:</p>
<div class="highlight-python"><div class="highlight"><pre>location /yourapplication/ {
    include fastcgi_params;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    fastcgi_param SCRIPT_NAME &quot;&quot;;
    fastcgi_pass unix:/tmp/yourapplication-fcgi.sock;
}
</pre></div>
</div>
<p>Since Nginx doesn&#8217;t load FastCGI apps, 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"><div class="highlight"><pre>$ screen
$ /var/www/yourapplication/yourapplication.fcgi
</pre></div>
</div>
</div>
<div class="section" id="debugging">
<h2>Debugging<a class="headerlink" href="#debugging" title="Permalink to this headline"></a></h2>
<p>FastCGI deployments tend to be hard to debug on most webservers.  Very often the
only thing the server log tells you is something along the lines of &#8220;premature
end of headers&#8221;.  In order to debug the application the only thing that can
really give you ideas why it breaks is switching to the correct user and
executing the application by hand.</p>
<p>This example assumes your application is called <cite>application.fcgi</cite> and that your
webserver user is <cite>www-data</cite>:</p>
<div class="highlight-python"><div class="highlight"><pre>$ su www-data
$ cd /var/www/yourapplication
$ python application.fcgi
Traceback (most recent call last):
  File &quot;yourapplication.fcg&quot;, line 4, in &lt;module&gt;
ImportError: No module named yourapplication
</pre></div>
</div>
<p>In this case the error seems to be &#8220;yourapplication&#8221; not being on the python
path.  Common problems are:</p>
<ul class="simple">
<li>relative paths being used.  Don&#8217;t rely on the current working directory</li>
<li>the code depending on environment variables that are not set by the
web server.</li>
<li>different python interpreters being used.</li>
</ul>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper"><p class="logo"><a href="../index.html">
  <img class="logo" src="../_static/werkzeug.png" alt="Logo"/>
</a></p>
  <h3><a href="../index.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">FastCGI</a><ul>
<li><a class="reference internal" href="#creating-a-fcgi-file">Creating a <cite>.fcgi</cite> file</a></li>
<li><a class="reference internal" href="#configuring-lighttpd">Configuring lighttpd</a></li>
<li><a class="reference internal" href="#configuring-nginx">Configuring nginx</a></li>
<li><a class="reference internal" href="#debugging">Debugging</a></li>
</ul>
</li>
</ul>
<h3>Related Topics</h3>
<ul>
  <li><a href="../index.html">Documentation overview</a><ul>
  <li><a href="index.html">Application Deployment</a><ul>
      <li>Previous: <a href="mod_wsgi.html" title="previous chapter"><cite>mod_wsgi</cite> (Apache)</a></li>
      <li>Next: <a href="proxying.html" title="next chapter">HTTP Proxying</a></li>
  </ul></li>
  </ul></li>
</ul>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/deployment/fastcgi.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <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="footer">
      &copy; Copyright 2011, The Werkzeug Team.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a>.
    </div>
  </body>
</html>