FastCGI部署Flask应用程序

2023-05-1514:54:27后端程序开发Comments1,063 views字数 1062阅读模式

FastCGI是Web服务器(如nginix,lighttpd和Cherokee)上Flask应用程序的另一个部署选项。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/39578.html

配置FastCGI

首先,需要创建FastCGI服务器文件,例如它的名称为:yourapplication.fcgiC文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/39578.html

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

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

nginx和较早版本的lighttpd需要明确传递一个套接字来与FastCGI服务器进行通信。需要将路径传递给WSGIServer的套接字。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/39578.html

WSGIServer(application, bindAddress = '/path/to/fcgi.sock').run()
Python

配置Apache

对于基本的Apache部署,.fcgi 文件将出现在您的应用程序URL中,例如http://example.com/yourapplication.fcgi/hello/。 有以下几种方法来配置应用程序,以便yourapplication.fcgi不会出现在URL中。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/39578.html

<VirtualHost *>
   ServerName example.com
   ScriptAlias / /path/to/yourapplication.fcgi/
</VirtualHost>
Shell

配置lighttpd

lighttpd的基本配置看起来像这样 -文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/39578.html

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,别名和重写模块。 该配置将应用程序绑定到/yourapplication文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/39578.html

//更多请阅读:https://www.yiibai.com/flask/flask_fastcgi.html文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/39578.html

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/bc/39578.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/bc/39578.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定