Code前端首页关于Code前端联系我们

FastCGI 部署 Flask 应用程序

terry 2年前 (2023-09-24) 阅读数 60 #后端开发

FastCGI 是 Fl​​ask 应用程序在 Nginix、lighttpd 和 Cherokee 等 Web 服务器上的另一个部署选项。

配置FastCGI

首先,您需要创建一个FastCGI服务器文件,其名称如下:yourapplication.fcgiC

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

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

nginx 和旧版本的 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>
Shell

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"
)
Shell

确保启用 FastCGI、别名和 rew。此配置将应用程序绑定到 /您的应用程序

//阅读更多:https://www.yiibai.com/flask/flask_fastcgi.html

版权声明

本文仅代表作者观点,不代表Code前端网立场。
本文系作者Code前端网发表,如需转载,请注明页面地址。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门