Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

deploying/fastcgi.rst done.

  • Loading branch information...
commit 6bd6fd63f6c116290811dac09edeeaf6b2c48ac7 1 parent a875c81
@dormouse authored
Showing with 37 additions and 52 deletions.
  1. +37 −52 FlaskDocsZhCn0.8/deploying/fastcgi.rst
89 FlaskDocsZhCn0.8/deploying/fastcgi.rst
@@ -19,8 +19,7 @@ FastCGI 也是部署 Flask 的途径之一。 Flask 的部署途径还有 `nginx
创建一个 `.fcgi` 文件
-First you need to create the FastCGI server file. Let's call it
+首先你必须创建 FastCGI 服务器配置文件,我们把它命名为 `yourapplication.fcgi`::
from flup.server.fcgi import WSGIServer
@@ -29,31 +28,27 @@ First you need to create the FastCGI server file. Let's call it
if __name__ == '__main__':
-This is enough for Apache to work, however nginx 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 :class:`~flup.server.fcgi.WSGIServer`::
+如果使用的是 Apache ,那么使用了这个文件之后就可以正常工作了。但是如果使用的是
+nginx 或老版本的 lighttpd ,那么需要显式地把接口传递给 FastCGI 服务器,即把接口
+的路径传递给 :class:`~flup.server.fcgi.WSGIServer`::
WSGIServer(application, bindAddress='/path/to/fcgi.sock').run()
-The path has to be the exact same path you define in the server
-Save the `yourapplication.fcgi` file somewhere you will find it again.
-It makes sense to have that in `/var/www/yourapplication` or something
+把这个 `yourapplication.fcgi` 文件放在一个以后可以找得到的地方,最好是
+`/var/www/yourapplication` 或类似的地方。
-Make sure to set the executable bit on that file so that the servers
-can execute it:
.. sourcecode:: text
# chmod +x /var/www/yourapplication/yourapplication.fcgi
-Configuring lighttpd
+配置 lighttpd
-A basic FastCGI configuration for lighttpd looks like that::
+一个 lighttpd 的基本 FastCGI 配置如下::
fastcgi.server = ("/yourapplication.fcgi" =>
@@ -72,25 +67,22 @@ A basic FastCGI configuration for lighttpd looks like that::
"^(/static.*)$" => "$1",
"^(/.*)$" => "/yourapplication.fcgi$1"
-Remember to enable the FastCGI, alias and rewrite modules. This
-configuration binds the application to `/yourapplication`. If you want
-the application to work in the URL root you have to work around a
-lighttpd bug with the
-:class:`~werkzeug.contrib.fixers.LighttpdCGIRootFix` middleware.
+请记住启用 FastCGI 、 alias 和 rewrite 模块。以上配置把应用绑定到
+`/yourapplication` 。如果你想要让应用在根 URL 下运行,那么必须使用
+:class:`~werkzeug.contrib.fixers.LighttpdCGIRootFix` 中间件来解决一个
+lighttpd 缺陷。
-Make sure to apply it only if you are mounting the application the URL
-root. Also, see the Lighty docs for more information on `FastCGI and
+请确保只有应用在根 URL 下运行时才使用上述中间件。更多信息请阅读 `FastCGI 和
Python <>`_
-(note that explicitly passing a socket to run() is no longer necessary).
+(注意,已经不再需要把一个接口显式传递给 run() 了)。
-Configuring nginx
+配置 nginx
-Installing FastCGI applications on nginx is a bit different because by
-default no FastCGI parameters are forwarded.
+在 nginx 上安装 FastCGI 应用有一些特殊,因为缺省情况下不传递 FastCGI 参数。
-A basic flask FastCGI configuration for nginx looks like this::
+一个 nginx 的基本 FastCGI 配置如下::
location = /yourapplication { rewrite ^ /yourapplication/ last; }
location /yourapplication { try_files $uri @yourapplication; }
@@ -102,9 +94,8 @@ A basic flask FastCGI configuration for nginx looks like this::
fastcgi_pass unix:/tmp/yourapplication-fcgi.sock;
-This configuration binds the application to `/yourapplication`. If you
-want to have it in the URL root it's a bit simpler because you don't
-have to figure out how to calculate `PATH_INFO` and `SCRIPT_NAME`::
+这个配置把应用绑定到 `/yourapplication` 。如果你想要在根 URL 下运行应用非常
+简单,因为你不必指出如何计算出 `PATH_INFO` 和 `SCRIPT_NAME`::
location / { try_files $uri @yourapplication; }
location @yourapplication {
@@ -114,32 +105,28 @@ have to figure out how to calculate `PATH_INFO` and `SCRIPT_NAME`::
fastcgi_pass unix:/tmp/yourapplication-fcgi.sock;
-Running FastCGI Processes
+运行 FastCGI 进程
-Since Nginx and others do not load FastCGI apps, you have to do it by
-yourself. `Supervisor can manage FastCGI processes.
+Nginx 和其他服务器不会载入 FastCGI 应用,你必须自己载入。 `Supervisor 可以管理
+FastCGI 进程。
-You can look around for other FastCGI process managers or write a script
-to run your `.fcgi` file at boot, e.g. using a SysV ``init.d`` script.
-For a temporary solution, you can always run the ``.fcgi`` script inside
-GNU screen. See ``man screen`` for details, and note that this is a
-manual solution which does not persist across system restart::
+在启动时你可以使用其他 FastCGI 进程管理器或写一个脚本来运行 `.fcgi` 文件,例如
+使用一个 SysV ``init.d`` 脚本。如果是临时使用,你可以在一个 GNU screen 中运行
+``.fcgi`` 脚本。运行细节参见 ``man screen`` ,同时请注意这是一个手动启动方法,
$ screen
$ /var/www/yourapplication/yourapplication.fcgi
-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 "premature end of headers". 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.
+在大多数服务器上, FastCGI 部署难以调试。通常服务器日志只会告诉你类似
+“ premature end of headers ”的内容。为了调试应用,查找出错的原因,你必须切换
-This example assumes your application is called `application.fcgi` and
-that your webserver user is `www-data`::
+下例假设你的应用是 `application.fcgi` ,且你的网络服务用户为 `www-data`::
$ su www-data
$ cd /var/www/yourapplication
@@ -148,13 +135,11 @@ that your webserver user is `www-data`::
File "yourapplication.fcgi", line 4, in <module>
ImportError: No module named yourapplication
-In this case the error seems to be "yourapplication" not being on the
-python path. Common problems are:
+上面的出错信息表示 "yourapplication" 不在 python 路径中。原因可能有:
-- Relative paths being used. Don't rely on the current working directory
-- The code depending on environment variables that are not set by the
- web server.
-- Different python interpreters being used.
+- 使用了相对路径。在当前工作路径下路径出错。
+- 当前网络服务器设置未正确设置环境变量。
+- 使用了不同的 python 解释器。
.. _nginx:
.. _lighttpd:
Please sign in to comment.
Something went wrong with that request. Please try again.