When running nginx + python flask + python-daemon: upstream sent unsupported FastCGI protocol version 91 When running nginx + python flask + python-daemon: upstream sent unsupported FastCGI protocol version 91 nginx nginx

When running nginx + python flask + python-daemon: upstream sent unsupported FastCGI protocol version 91


It turns out that DaemonContext closes any opened file descriptors, so basically there should be a function, that instantiates WSGIServer, together with app аnd everything that could open a file descriptor INSIDE the DaemonContext.

Also make sure the working directory is such that is owned by the user or at least has permissions allowing the user with given UID to write there (not recommended).

Example:

#!/usr/bin/env pythonimport argparse, daemon, osfrom flup.server.fcgi import WSGIServerfrom fwd_msg import appSOCKET_LOCATION = '/tmp/fingerprinter-fcgi.sock'def main():    app = flask.Flask(__name__)    @app.route('/', methods=['GET'])    def index():        pass # your actions hereif __name__ == '__main__':    # arg parse (and daemonize)    arg_parser = argparse.ArgumentParser()    arg_parser.add_argument('--daemon', action='store_true', default=False, help='Run as daemon')    arg_parser.add_argument('--cwd', action='store', default='/',                             help='Full path of the working directory to which the process should change on daemon start.')    arg_parser.add_argument('--uid', action='store', type=int, default=os.getuid(),        help='The user ID ("UID") value and group ID ("GID") value to switch the process to on daemon start.')    args = vars(arg_parser.parse_args())    if args['daemon']:        context = daemon.DaemonContext(working_directory=args['cwd'], uid=args['uid'])        with context:            main()    else:        main()