使用 fastcgi 将 Lighttpd 配置为 运行 python 脚本

Configure Lighttpd to run python script using fastcgi

我有一个 lighttpd 服务器,我想 运行 一个使用 fastcgi 的 python 应用程序。我遵循 example on the lighty homepage,但似乎无法轻松执行 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()

当我使用此配置重新启动 lig​​hty 时,我可以看到 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 

当 lighttpd 使用 "bin-path"

启动 FastCGI 时,不应在 WSGIServer() Python 代码中指定 bindaddress