[英]Flask app deployment with lighttpd results in error
我正在嘗試在 Raspberry Pi 上使用 lighttpd 和 fastcgi 部署我的 flask 應用程序。 不幸的是,我無法讓它工作。 這是我的程序:
sudo apt install lighttpd
pip install flup
創建 /var/www/demoapp/hello.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World"
if __name__ == "__main__":
app.run()
創建 /var/www/demoapp/hello.fcgi
#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from hello import app
if __name__ == '__main__':
WSGIServer(app).run()
將以下內容添加到 /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"
)
要重新加載配置,使用sudo /etc/init.d/lighttpd restart
網絡服務器
然后我希望我可以訪問 raspberrypi.local raspberrypi.local/static
下的應用程序,我只是通過 Chrome 獲得ERR_EMPTY_RESPONSE
。
你能發現我的程序有什么問題嗎? 我錯過了什么?
謝謝你的幫助!
重寫后,lighttpd 在內部重新處理請求,因此刪除“/static”前綴的重寫將不匹配“/static”前綴的別名,因為“/static”前綴在重寫后不再存在。
if $HTTP["url] !~ "^/static($|/)" {
url.rewrite-once = (
"^/hello.fcgi" => "",
"^(/.*)$" => "/hello.fcgi$1"
)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.