1

I'm trying to deploy my flask web app using lighttpd. I created this hello.fcgi file

#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from hello import app

if __name__ == '__main__':
    WSGIServer(app).run()

And python file is hello.py

I added these lines at the end of the /etc/lighttpd/lighttpd.conf. I wanted it to be accessible from http://localhost:7777.

$SERVER["socket"] == ":7777" {
    fastcgi.server = ("/hello.fcgi" =>
        ((
            "socket" => "/tmp/hello-fcgi.sock",
            "bin-path" => "/var/www/html/py/hello.fcgi",
            "check-local" => "disable",
            "max-procs" => 1
        ))
    )

    alias.url = (
        "/static/" => "/var/www/html/py/static"
    )

    url.rewrite-once = (
        "^(/static($|/.*))$" => "$1",
        "^(/.*)$" => "/hello.fcgi$1"
    )
}

I also enabled enable the FastCGI, alias and rewrite modules. All the files of my web app is located inside /var/www/html/py/ folder including hello.py , hello.fcgi and the "static" folder.

Then I restarted lighttpd and tried to visit http://localhost:7777 but my browser says "This site can’t be reached".

What is wrong here and how can I fix it?

1 Answers1

0

Know this is late, but came across this when searching another problem and figured I would post the fix here which is documented in the Python Flask documentation for Lighttpd.

#!/usr/bin/env python3
from flup.server.fcgi import WSGIServer
from hello import app


class ScriptNameStripper(object):
    def __init__(self, app):
        self.app = app

    def __call__(self, environ, start_response):
        environ['SCRIPT_NAME'] = ''
        return self.app(environ, start_response)


app = ScriptNameStripper(app)

if __name__ == '__main__':
    WSGIServer(app).run()