0
votes

I'm trying to deploy my flask app with lighttpd and fastcgi on a Raspberry Pi. Unfortunately I can not get it to work. Here my procedure:

  • I installed lighttpd with sudo apt install lighttpd
  • I installed flup with pip install flup

created /var/www/demoapp/hello.py

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World"

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

created /var/www/demoapp/hello.fcgi

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

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

added the follwoing to /etc/lighttpd/lighttpd.conf

fastcgi.server = ("/hello.fcgi" => ((
   "socket" => "/tmp/hello-fcgi.sock",
   "bin-path" => "/var/www/demoapp/hello.fcgi",
   "check-local" => "disable",
   "max-procs" => 1
)))

alias.url += (
   "/static" => "/var/www/demoapp/static"
)

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

To reload the configuration the webserver is restarted with sudo /etc/init.d/lighttpd restart

Then I expect that I can access the app under raspberrypi.local/static I just get a ERR_EMPTY_RESPONSE by Chrome.

Can you spot something that is wrong in my procedure? Did I miss something?

Thanks for your help!

1

1 Answers

0
votes

After a rewrite, lighttpd internally reprocesses the request so the rewrite to remove the "/static" prefix WILL NOT MATCH the alias for the "/static" prefix, since the "/static" prefix no longer exists after the rewrite.

if $HTTP["url] !~ "^/static($|/)" {
    url.rewrite-once = (
       "^/hello.fcgi" => "",
       "^(/.*)$" => "/hello.fcgi$1"
    )
}