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