📜  Flask – FastCGI

📅  最后修改于: 2020-10-25 11:36:18             🧑  作者: Mango


FastCGI是Web服务器(例如nginix,lighttpd和Cherokee)上Flask应用程序的另一个部署选项。

配置FastCGI

首先,您需要创建FastCGI服务器文件。让我们将其称为yourapplication.fcgi

from flup.server.fcgi import WSGIServer
from yourapplication import app

if __name__ == '__main__':
   WSGIServer(app).run()

nginx的和旧版本的lighttpd的需要插座必须显式传递与FastCGI的服务器进行通信。为此,您需要将套接字的路径传递给WSGIServer

WSGIServer(application, bindAddress = '/path/to/fcgi.sock').run()

配置Apache

对于基本的Apache部署,您的.fcgi文件将出现在您的应用程序URL中,例如example.com/yourapplication.fcgi/hello/ 。有几种方法可以配置您的应用程序,以使yourapplication.fcgi不会出现在URL中。


   ServerName example.com
   ScriptAlias / /path/to/yourapplication.fcgi/

配置lighttpd

lighttpd的基本配置如下所示:

fastcgi.server = ("/yourapplication.fcgi" => ((
   "socket" => "/tmp/yourapplication-fcgi.sock",
   "bin-path" => "/var/www/yourapplication/yourapplication.fcgi",
   "check-local" => "disable",
   "max-procs" => 1
)))

alias.url = (
   "/static/" => "/path/to/your/static"
)

url.rewrite-once = (
   "^(/static($|/.*))$" => "$1",
   "^(/.*)$" => "/yourapplication.fcgi$1"
)

记住要启用FastCGI ,别名和重写模块。此配置将应用程序绑定到/ yourapplication