Python Flask框架学习25:Flask FastCGI

32 篇文章 3 订阅

Flask FastCGI

FastCGI是在nginx,lighttpd和Cherokee等web服务器上的Flask应用程序的另一个部署选项。

配置FastCGI

首先,您需要创建FastCGI服务器文件。让我们称之为yourapplication.fcgiC

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,alias和rewrite模块。此配置将应用程序绑定到/yourapplication

更多内容,可关注作者的微信公众号:胖哥真不错。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值