FastCGI 部署 Flask 应用程序
FastCGI 是 Flask 应用程序在 Nginix、lighttpd 和 Cherokee 等 Web 服务器上的另一个部署选项。
配置FastCGI
首先,您需要创建一个FastCGI服务器文件,其名称如下:yourapplication.fcgiC。
from flup.server.fcgi import WSGIServer
from yourapplication import app
if __name__ == '__main__':
WSGIServer(app).run()
Pythonnginx 和旧版本的 lighttpd 明确需要套接字与 FastCGI 服务器通信。该路径必须传递到 WSGIServer 接口。
WSGIServer(application, bindAddress = '/path/to/fcgi.sock').run()
Python配置 Apache
在基本 Apache 安装中,.fcgi 文件出现在应用程序的 URL 中,例如 http://yexplication.com。 fcgi/你好/。有多种方法可以配置应用程序,以便 myapp.fcgi
不会出现在 URL 中。配置
<VirtualHost *>
ServerName example.com
ScriptAlias / /path/to/yourapplication.fcgi/
</VirtualHost>
Shelllighttpd
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"
)
Shell 确保启用 FastCGI、别名和 rew。此配置将应用程序绑定到 /您的应用程序
。
//阅读更多:https://www.yiibai.com/flask/flask_fastcgi.html
版权声明
本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。
上一篇:Flask 应用的部署 下一篇:Flask 初学者指南:开发 Sijax 应用程序
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。