目录

flask - FastCGI( FastCGI)

FastCGI是Nginix,lighttpd和Cherokee等Web服务器上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中。

<VirtualHost *>
   ServerName example.com
   ScriptAlias//path/to/yourapplication.fcgi/
</VirtualHost>

配置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的应用程序。

↑回到顶部↑
WIKI教程 @2018