Flask FastCGI


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