Configure Lighttpd to Run Python Script Using Fastcgi

Configure Lighttpd to Run Python Script Using Fastcgi

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 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.

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 
2

1 Answer

Per your fcgitest.py,

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

None of the examples include the bindAddress parameter that you have here.

Try this instead,


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.