FastCGI是Web服务器(例如nginx,lighttpd和Cherokee)上Flask应用程序的另一个部署选项。
首先,您需要创建 FastCGI 服务器文件。让无涯教程将其称为 yourapplication.fcgi 。
from flup.server.fcgi import WSGIServer from yourapplication import app if __name__ == '__main__': WSGIServer(app).run()
nginx 和更低版本的 lighttpd 需要显式传递一个Socket才能与 FastCGI 服务器进行通信。为此,您需要将Socket的路径传递到 WSGIServer 。
WSGIServer(application, bindAddress='/path/to/fcgi.sock').run()
对于基本的Apache部署,您的 .fcgi 文件将显示在应用程序URL中,如 example.com/yourapplication.fcgi/hello/。很少有方法可以配置您的应用程序,以使 yourapplication.fcgi 不会出现在URL中。
链接:https://www.learnfk.comhttps://www.learnfk.com/flask/flask-fastcgi.html
来源:LearnFk无涯教程网
<VirtualHost *> ServerName example.com ScriptAlias//path/to/yourapplication.fcgi/ </VirtualHost>
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 ,别名和重写模块。此配置将应用程序绑定到 /您的应用程序。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)