Python flask & fast-cgi on apache - 500 Internal Server Error (Premature end of script headers) -


i want setup flask app on apache prodcution server. have created following .htaccess file:

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

which should redirect following fcgi file (set chmod 755):

#!/usr/bin/env python2.7 # -*- coding: utf-8 -*-  relative_web_url_path = '/app_dict'  import os # points application on local filesystem. local_application_path = os.path.expanduser('~') + '/html/app_dict' import sys sys.path.insert(0, local_application_path)  flup.server.fcgi import wsgiserver 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() 

which in return should start following flask app:

#!/usr/bin/env python2.7 # -*- coding: utf8 -*-  flask import flask app = flask(__name__)  @app.route("/") def hello():     return "hello world!" 

but when try access website, internal server error 500 shown. , following lines show in apache error log:

[warn] [client 0.0.0.0] (104)connection reset peer: mod_fcgid: error reading data fastcgi server [error] [client 0.0.0.0] premature end of script headers: runflaskapp.fcgi 

if run fcgi file with"python2.7 runflaskapp.fcgi" returns following:

wsgiserver: missing fastcgi param request_method required wsgi! wsgiserver: missing fastcgi param server_name required wsgi! wsgiserver: missing fastcgi param server_port required wsgi! wsgiserver: missing fastcgi param server_protocol required wsgi! status: 200 ok content-type: text/html; charset=utf-8 content-length: 12  hello world! 

i belive header errors because it´s not run in context of wsgiserver.

i tried provoke exception in flask app adding wrong formated line of code. no exception shows in apache error log. lead me belive flask app isnt´t loaded fcgi script.

is there way debug further, or know solution problem?

the problem rights or line endings of fcgi file. uploading windows server , setting chmod 755 dosn´t work. creating file on server , running chmod 755 worked me.


Comments