在 Windows 下使用 fastcgi 和 Apache 部署 flask 应用程序

Deploy flask application with fastcgi and Apache under Windows

我正在尝试使用 fastcgi 在 apache 上部署我的 flask 应用程序。

OS: Windows 10 python2.7

apache 路径:E:\development\webservices\apache\bin\httpd.exe

Python路径:C:\Python27\python.exe

我正在为 运行 fastcgi (E:\development\webservices\apache\modules\mod_fcgid.so)

使用 mod mod_fcgid 2.3.9

我的fastcgi conf(E:\development\webservices\apache\conf\extra\httpd-fastcgi.conf)

FcgidInitialEnv PATH "e:/development/webservices/php;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;C:/Python27/;C:/Python27/Scripts;"
FcgidInitialEnv SystemRoot "C:/Windows"
FcgidInitialEnv SystemDrive "C:"
FcgidInitialEnv TEMP "C:/WINDOWS/Temp"
FcgidInitialEnv TMP "C:/WINDOWS/Temp"
FcgidInitialEnv windir "C:/WINDOWS"
FcgidIOTimeout 64
FcgidConnectTimeout 16
FcgidMaxRequestsPerProcess 1000 
FcgidMaxProcesses 50 
FcgidMaxRequestLen 8131072
# Location php.ini:
FcgidInitialEnv PHPRC "e:/development/webservices/php"
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 1000

<Files ~ "\.php$>"
  AddHandler fcgid-script .php
  FcgidWrapper "e:/development/webservices/php/php-cgi.exe" .php
</Files>

我的httpd.conf:

Listen 5000
LoadModule fcgid_module modules/mod_fcgid.so
# FastCGI
Include conf/extra/httpd-fastcgi.conf
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

我的httpd-vhosts.conf:

<VirtualHost *:5000>
    ServerName localhost:5000
    DocumentRoot c:/myproject/app
    ScriptAlias / c:/myproject/app/runserver.fcgi/

<Directory "c:/myproject/app/">
   AllowOverride None
   Allow from all
   Options +ExecCGI
   AddHandler fcgid-script .fcgi
   Require all granted
</Directory>

</VirtualHost>

我的 flask 应用程序位于:C:\myproject\app

它具有以下结构:

app\
    runserver.py
    runserver.fcgi
    gallery\
    image_hosting\
                   images\
                   static\
                           css\
                           jmg\
                           js\
                   templates\
                   init.py
                   forms.py
                   models.py
                   routes.py

runserver.fcgi内容:

#!C:/Python27/python.exe
# -*- coding: utf-8 -*-
import os
from flup.server.fcgi import WSGIServer
from image_hosting import app

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

当我尝试访问 localhost:5000 时,出现 500 内部服务器错误

Apache 错误日志:

AH00558: httpd.exe: Could not reliably determine the server's fully qualified domain name, using fe80::680d:ad2a:63e8:99bd. Set the 'ServerName' directive globally to suppress this message
[Mon Apr 18 12:36:20.405465 2016] [mpm_winnt:notice] [pid 20032:tid 668] AH00455: Apache/2.4.20 (Win64) mod_fcgid/2.3.9 configured -- resuming normal operations
[Mon Apr 18 12:36:20.405465 2016] [mpm_winnt:notice] [pid 20032:tid 668] AH00456: Apache Lounge VC14 Server built: Apr  5 2016 13:15:28
[Mon Apr 18 12:36:20.405465 2016] [core:notice] [pid 20032:tid 668] AH00094: Command line: 'E:\development\webservices\apache\bin\httpd.exe -d E:/development/webservices/apache'
[Mon Apr 18 12:36:20.406460 2016] [mpm_winnt:notice] [pid 20032:tid 668] AH00418: Parent: Created child process 3788
AH00558: httpd.exe: Could not reliably determine the server's fully qualified domain name, using fe80::680d:ad2a:63e8:99bd. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd.exe: Could not reliably determine the server's fully qualified domain name, using fe80::680d:ad2a:63e8:99bd. Set the 'ServerName' directive globally to suppress this message
[Mon Apr 18 12:36:20.702847 2016] [mpm_winnt:notice] [pid 3788:tid 648] AH00354: Child: Starting 64 worker threads.
[Mon Apr 18 12:36:21.444860 2016] [mpm_winnt:notice] [pid 7552:tid 652] AH00364: Child: All worker threads have exited.
[Mon Apr 18 12:36:28.178274 2016] [fcgid:warn] [pid 3788:tid 1172] (OS 109)The pipe has been ended.  : [client ::1:56818] mod_fcgid: get overlap result error
[Mon Apr 18 12:36:28.178274 2016] [core:error] [pid 3788:tid 1172] [client ::1:56818] End of script output before headers: runserver.fcgi

有人可以向我解释一下问题出在哪里吗?我该如何解决?

flup 显然不支持Windows。我真是太傻了。