busterroni
busterroni

Reputation: 663

web.py and lighttpd error: Connection refused, child exited: 1

I'm running web.py with lighttpd with very similar config to what's suggested on the website. When I run it with /etc/init.d/lighttpd start I get these errors in the logs:

2022-11-07 21:30:59: (gw_backend.c.528) connect /tmp/fastcgi.socket-0: Connection refused
2022-11-07 21:30:59: (gw_backend.c.371) child exited: 1 unix:/tmp/fastcgi.socket-0
2022-11-07 21:30:59: (gw_backend.c.512) new proc, socket: 0 /tmp/fastcgi.socket-0
2022-11-07 21:30:59: (gw_backend.c.528) connect /tmp/fastcgi.socket-0: Connection refused
2022-11-07 21:30:59: (gw_backend.c.371) child exited: 1 unix:/tmp/fastcgi.socket-0

It works when I test it with lighttpd -D -f /etc/lighttpd/lighttpd.conf.

My python file starts with #!/usr/bin/env python3 and is executable.

Upvotes: 0

Views: 341

Answers (1)

busterroni
busterroni

Reputation: 663

The program was failing because environment variables weren't being passed. I don't love the current resolution, and I plan on coming back to it later. For now, I set environment variables in lighttpd.conf. In /etc/lighttpd/lighttpd.conf (good links for reference webpy.org ongspxm.gitlab.io):

fastcgi.server = (
    "/app.py" => (
        "webpy" => (
            "socket" => "/tmp/fastcgi.socket",
            "min-procs" => 1,
            "bin-path" => "PATH_TO_CODE/app.py",
            "bin-environment" => (
                "REAL_SCRIPT_NAME" => "",
                "ENVIRONMENT_VARIABLE_A" => "example_a",
                "ENVIRONMENT_VARIABLE_B" => "example_b"
            )
        )
    )
)

To debug this I made a simple web.py app (mostly from the homepage) and outputted the environment variables. It might help you debug:

#!/usr/bin/env python3.10

import web
import os
urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello:
    def GET(self, name):
        if not name:
            name = 'World'
        return str(os.environ)

if __name__ == "__main__":
    app.run()

More info on REAL_SCRIPT_NAME: lighttpd, mod_rewrite, web.py

/etc/init.d/lighttpd status was helpful for figuring out the issue.

Changing #!/usr/bin/env python3 to #!/usr/bin/env python3.10 fixed it. Unfortunately I'm not sure why.

Upvotes: 0

Related Questions