English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Flask FastCGI

FastCGI는 Web 서버(예: nginix, lighttpd, Cherokee)에서 Flask 애플리케이션의 또 다른 배포 옵션입니다.

FastCGI를 설정하십시오

먼저, FastCGI 서버 파일을 생성해야 합니다. 예를 들어, 그 이름은: yourapplication.fcgiC .

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

nginx와 이전 버전의 lighttpd는 FastCGI 서버와 통신하기 위해 명확히 소켓을 전달해야 합니다. WSGIServer의 소켓에 경로를 전달해야 합니다.

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

Apache를 설정하십시오

기본적인 Apache 배포에 대해 .fcgi 파일은 귀하의 애플리케이션 URL에 표시됩니다. 예를 들어 http://example.com/yourapplication.fcgi/헬로/다음과 같은 방법으로 애플리케이션을 설정하여 yourapplication.fcgi가 URL에 표시되지 않도록 할 수 있습니다.

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

lighttpd 설정

lighttpd 기본 설정은 이렇게 보입니다 -

# Filename : example.py
# Copyright : 2020 By w3codebox
# Author by : ko.oldtoolbag.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"
 )

FastCGI를 활성화하고 별명 및 리워트 모듈을 기억하세요. 이 설정은 애플리케이션을/yourapplication。