Flask FastCGI

Flask教程 · 2019-04-26 06:16:30

FastCGI是Web服务器(如nginix,lighttpd和Cherokee)上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中,例如http://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,别名和重写模块。 该配置将应用程序绑定到/yourapplication

点击查看所有 Flask教程 文章: https://codercto.com/courses/l/47.html

查看所有标签

高扩展性网站的50条原则

高扩展性网站的50条原则

[美] Martin L. Abbott、[美]Michael T. Fisher / 张欣、杨海玲 / 人民邮电出版社 / 2012-6-3 / 35.00元

《高扩展性网站的50条原则》给出了设计高扩展网站的50条原则,如不要过度设计、设计时就考虑扩展性、把方案简化3倍以上、减少DNS查找、尽可能减少对象等,每个原则都与不同的主题绑定在一起。大部分原则是面向技术的,只有少量原则解决的是与关键习惯和方法有关的问题,当然,每个原则都对构建可扩展的产品至关重要。 主要内容包括: 通过克隆、复制、分离功能和拆分数据集提高网站扩展性; 采用横向......一起来看看 《高扩展性网站的50条原则》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码