我想在apache prodcution服务器上安装我的flask应用程序。我创建了以下内容。htaccess文件:
<IfModule mod_fcgid.c>
AddHandler fcgid-script .fcgi
<Files ~ (\.fcgi)>
SetHandler fcgid-script
Options +SymLinksIfOwnerMatch +ExecCGI
</Files>
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /fcgi-bin/runFlaskApp.fcgi/$1 [QSA,L]
</IfModule>
应重定向到以下fcgi文件(设置为chmod 755):
#!/usr/bin/env python2.7
# -*- coding: UTF-8 -*-
RELATIVE_WEB_URL_PATH = '/app_dict'
import os
# This points to the application on the local filesystem.
LOCAL_APPLICATION_PATH = os.path.expanduser('~') + '/html/app_dict'
import sys
sys.path.insert(0, LOCAL_APPLICATION_PATH)
from flup.server.fcgi import WSGIServer
from tmain import app
class ScriptNamePatch(object):
def __init__(self, app):
self.app = app
def __call__(self, environ, start_response):
environ['SCRIPT_NAME'] = RELATIVE_WEB_URL_PATH
return self.app(environ, start_response)
app = ScriptNamePatch(app)
if __name__ == '__main__':
WSGIServer(app).run()
#!/usr/bin/env python2.7
# -*- coding: utf8 -*-
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
但当我尝试访问该网站时,显示了一个内部服务器错误500。apache错误日志中显示以下行:
[warn] [client 0.0.0.0] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[error] [client 0.0.0.0] Premature end of script headers: runFlaskApp.fcgi
如果我用“python2.7 runFlaskApp.fcgi”运行fcgi文件,它将返回以下内容:
WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 12
Hello World!
有没有办法进一步调试这个问题,或者有人知道这个问题的解决方案吗?