Flask FastCGI

FastCGI是Web服務(wù)器(如nginix,lighttpd和Cherokee)上Flask應(yīng)用程序的另一個(gè)部署選項(xiàng)。

配置FastCGI

首先,需要?jiǎng)?chuàng)建FastCGI服務(wù)器文件,例如它的名稱為: yourapplication.fcgiC 。

# Filename : example.py
# Copyright : 2020 By Nhooo
# Author by : www.soo66.com
# Date : 2020-08-08
from flup.server.fcgi import WSGIServer
 from yourapplication import app
 if __name__ == '__main__':
     WSGIServer(app).run()

nginx和較早版本的lighttpd需要明確傳遞一個(gè)套接字來(lái)與FastCGI服務(wù)器進(jìn)行通信。需要將路徑傳遞給WSGIServer的套接字。

# Filename : example.py
# Copyright : 2020 By Nhooo
# Author by : www.soo66.com
# Date : 2020-08-08
WSGIServer(application, bindAddress = '/path/to/fcgi.sock').run()

配置Apache

對(duì)于基本的Apache部署, .fcgi 文件將出現(xiàn)在您的應(yīng)用程序URL中,例如http://example.com/yourapplication.fcgi/hello/。 有以下幾種方法來(lái)配置應(yīng)用程序,以便yourapplication.fcgi不會(huì)出現(xiàn)在URL中。

# Filename : example.py
# Copyright : 2020 By Nhooo
# Author by : www.soo66.com
# Date : 2020-08-08
<VirtualHost *>
    ServerName example.com
    ScriptAlias / /path/to/yourapplication.fcgi/
 </VirtualHost>

配置lighttpd

lighttpd的基本配置看起來(lái)像這樣 -

# Filename : example.py
# Copyright : 2020 By Nhooo
# Author by : www.soo66.com
# Date : 2020-08-08
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"
 )

請(qǐng)記住啟用FastCGI,別名和重寫模塊。 該配置將應(yīng)用程序綁定到/yourapplication。

丰满人妻一级特黄a大片,午夜无码免费福利一级,欧美亚洲精品在线,国产婷婷成人久久Av免费高清