fastcgi是web服务器(如nginix,lighttpd和cherokee)上flask应用程序的另一个部署选项。
首先,需要创建fastcgi服务器文件,例如它的名称为: yourapplication.fcgic 。
# filename : example.py # j9九游会老哥俱乐部交流区 copyright : 2020 by nhooo # author by : https://www.elefans.com/biancheng/ # date : 2020-08-08 from flup.server.fcgi import wsgiserver from yourapplication import app if __name__ == '__main__': wsgiserver(app).run()
nginx和较早版本的lighttpd需要明确传递一个套接字来与fastcgi服务器进行通信。需要将路径传递给wsgiserver的套接字。
# filename : example.py # j9九游会老哥俱乐部交流区 copyright : 2020 by nhooo # author by : https://www.elefans.com/biancheng/ # date : 2020-08-08 wsgiserver(application, bindaddress = '/path/to/fcgi.sock').run()
对于基本的apache部署, .fcgi 文件将出现在您的应用程序url中,例如http://example.com/yourapplication.fcgi/hello/。 有以下几种方法来配置应用程序,以便yourapplication.fcgi不会出现在url中。
# filename : example.py # j9九游会老哥俱乐部交流区 copyright : 2020 by nhooo # author by : https://www.elefans.com/biancheng/ # date : 2020-08-08servername example.com scriptalias / /path/to/yourapplication.fcgi/
lighttpd的基本配置看起来像这样 -
# filename : example.py # j9九游会老哥俱乐部交流区 copyright : 2020 by nhooo # author by : https://www.elefans.com/biancheng/ # date : 2020-08-08 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。