fastcgi を使用して Python スクリプトを実行するように Lighttpd を設定する

fastcgi を使用して Python スクリプトを実行するように Lighttpd を設定する

私はlighttpdサーバーを持っていて、fastcgiを使ってPythonアプリケーションを実行したいと考えています。lightyホームページの例しかし、どうやら lighty で Python スクリプトを実行できないようです。これは lighttpd.conf の fastcgi セクションです:

fastcgi.server = (
    ".py" =>
    (
        "python-fcgi" =>
        (
         "socket" => "/tmp/fastcgi.python.socket",
         "bin-path" => "/usr/bin/login_flask/fcgitest.py",
         "check-local" => "disable",
         "max-procs" => 1,
        )
    ))

fcgitest.py の内容は次のとおりです。

#!/usr/bin/python3
def myapp(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return ['Hello World!\n']

if __name__ == '__main__':
    from flup.server.fcgi import WSGIServer
    WSGIServer(myapp, bindAddress="/tmp/fastcgi.python.socket").run()

この設定でlightyを再起動すると、pythonプロセスが開始され、lightyからエラーは発生しません。しかし、https://localhost:444/test.py永遠にロードが続きます。access.log や error.log には何も書き込まれません。この調査方法についてヒントをいただける方がいらっしゃいましたら、大変助かります。

編集: fastcgi.debug を有効にしましたが、上記の URL にアクセスすると、次のエラーがエラー ログに書き込まれます。それでも読み込みは永遠に続きます:

2019-07-26 11:53:26: (gw_backend.c.914) gw - found a host  0 
2019-07-26 11:53:26: (gw_backend.c.227) got proc: pid: 2628 socket: unix:/tmp/fastcgi.python.socket-0 load: 1 

答え1

あなたのfcgitest.py

if __name__ == '__main__':
    from flup.server.fcgi import WSGIServer
    WSGIServer(myapp, bindAddress="/tmp/fastcgi.python.socket").run()

いずれの例にも、bindAddressここに示すパラメータは含まれていません。

代わりにこれを試してください。


if __name__ == '__main__':
    from flup.server.fcgi import WSGIServer
    WSGIServer(myapp).run()

関連情報