2012-05-09 21 views
3

私はnginxでFCGIを使ってPython Flaskを使ってWeb用Pythonを実行しています。私のfcgiバックエンドは次のように設定されています。nginx + pythonフラスコ+ pythonデーモンを実行しているとき:アップストリームでサポートされていないFastCGIプロトコルのバージョン91

#!/usr/bin/env python 
import argparse, daemon, os 
from flup.server.fcgi import WSGIServer 
from fwd_msg import app 

SOCKET_LOCATION = '/tmp/fingerprinter-fcgi.sock' 

if __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: 
      WSGIServer(app, bindAddress=SOCKET_LOCATION).run() 
    else: 
     WSGIServer(app, bindAddress=SOCKET_LOCATION).run() 

デーモン引数なしでWSGIServerを実行するとうまくいきます。

しかし、私はデーモンの引数でそれを実行した場合、「502 BAD GATEWAY」を使用してサーバー側に何らかの要求しながら、私は、nginxのログにこのエラーが表示されます。

2012/05/09 12:16:00 [error] 30895#0: *30 upstream sent unsupported FastCGI protocol version: 91 while reading response header from upstream, client: XXX.XXX.XXX.XXX, server: localhost, request: "POST/HTTP/1.1", upstream: "fastcgi://unix:/tmp/fingerprinter-fcgi.sock:", host: "XXX.XXX.XXX.XXX" 

すべてのアイデア、なぜこの出来事であり、どのようにそれを防ぐために?

+0

あなたはCWDとのuidとビットを再生する場合、それは何も変更していますか?たとえば、他の値を渡すと、デフォルト値が1になります。最悪の場合、 'strace -fo/tmp/log XXXXX yyyy'を実行してください。 – bluszcz

答えて

0

DaemonContextは開いているファイルディスクリプタを閉じます。したがって、基本的には、アプリケーションとDaemonContextの中にファイルディスクリプタを開くことができるすべてのものとともに、WSGIServerをインスタンス化する関数が存在する必要があります。

また、作業ディレクトリがユーザーの所有するものであるか、少なくとも与えられたUIDを持つユーザーがそこに書き込むことを許可するアクセス許可があることを確認してください(推奨されません)。

例:

#!/usr/bin/env python 
import argparse, daemon, os 
from flup.server.fcgi import WSGIServer 
from fwd_msg import app 

SOCKET_LOCATION = '/tmp/fingerprinter-fcgi.sock' 

def main(): 
    app = flask.Flask(__name__) 
    @app.route('/', methods=['GET']) 
    def index(): 
     pass # your actions here 

if __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() 
関連する問題