Apache烧瓶&fast-cgi-500内部服务器错误(脚本头过早结束)

问题描述:

我想在apache prodcution服务器上设置烧瓶应用程序。我创建了以下.htaccess文件:Apache烧瓶&fast-cgi-500内部服务器错误(脚本头过早结束)

<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! 

我相信头错误是因为它没有在WSGIServer的上下文中运行。

我已经试图通过添加一个错误的格式化代码行来挑起烧瓶应用程序中的异常。但是在apache错误日志中没有出现异常。这让我相信烧瓶应用程序甚至不会被fcgi脚本加载。

有没有办法进一步调试这个问题,还是有人知道这个问题的解决方案?

问题在于fcgi文件的权限或行结束。将它从Windows上传到服务器并设置chmod 755 dosn't工作。 只在服务器上创建文件,然后运行chmod 755为我工作。