設定 Lighttpd 使用 fastcgi 執行 python 腳本

設定 Lighttpd 使用 fastcgi 執行 python 腳本

我有一個 lighttpd 伺服器,我想使用 fastcgi 運行 python 應用程式。我跟著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()

相關內容