Project

General

Profile

[Solved] Configure Lighttpd to run python script using fastcgi

Added by Gasp0de over 4 years ago

I have a lighttpd server that I want to run a python application using fastcgi. I followed the example on the lighty homepage, but I can't seem to get lighty to execute the python script. This is my fastcgi section in lighttpd.conf:

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

This is the content of 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()

When I restart lighty with this configuration, I can see that the python process is started and I don't get any error from lighty. However, when I go to https://localhost:444/test.py it just keeps loading forever. Nothing is written in access.log or error.log. If anyone could give me a hint on how to investigate this I would be grateful. Thank you :)

EDIT: I enabled fastcgi.debug, and this is written to the error log when I go to the URL mentioned above. It still keeps loading forever:

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


Replies (2)

RE: Configure Lighttpd to run python script using fastcgi - Added by gstrauss over 4 years ago

bindaddress should not be specified in WSGIServer() Python code when lighttpd starts up the FastCGI using "bin-path"

    (1-2/2)