在 lighttpd 和树莓派上部署 Flask [英] Flask deployement on lighttpd and raspberry pi

查看:50
本文介绍了在 lighttpd 和树莓派上部署 Flask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 lighttpd fastCGI 将 hello flask 应用程序部署到 raspberry pi.

I'm trying to deploy a hello flask app to a raspberry pi using lighttpd fastCGI.

我按照 http://flask.pocoo.org/docs 上的说明进行操作/0.10/deploying/fastcgi/ 尽我所能

这是我的烧瓶应用程序 (/var/www/demoapp/hello.py)

Here is my flask app (/var/www/demoapp/hello.py)

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World From Flask Yeh!"

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=5000)

这是我的 .fcgi 文件 (/var/www/demoapp/hello.fcgi)

And here is my .fcgi file (/var/www/demoapp/hello.fcgi)

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

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

这是我添加到/etc/lighttpd/lighttpd.conf 中的内容

And here is what I added to my /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/",
)

我收到 404 Not Found 错误

I get a 404 Not Found error

顺便说一下,/tmp/hello-fcgi.sock 是什么,我从哪里得到这个文件

By the way what is the /tmp/hello-fcgi.sock where do I get this file

请帮忙.我基本上是想找到一种简单的方法来在我的树莓派 Web 服务器上部署烧瓶.我尝试了几种方法.fastcgi 似乎是最简单的.如果有更简单的方法,请告诉我.

Please help. I'm essentially trying to find a simple way to deploy flask on my raspberry pi web server. I have tried several methods. The fastcgi seemed to be the easiest. If there is an easier way then let me know please.

谢谢

文森特

推荐答案

我相信问题是在你的 hello.fcgi 文件中,你正在导入一个名为 yourapplication 的模块,但是,flask 应用程序您创建的名为 hello.

I believe the problem is that in your hello.fcgi file, you are importing a module named yourapplication, however, the flask application you created is named hello.

尝试更改此行:

从你的应用导入应用从你好导入应用

另外 - 在测试时仔细检查您的网址 - 由于您的 @app.route 设置为根,您必须在您的网址中包含尾部斜杠,例如:

Also - double check your url when testing - since your @app.route is set to the root, you must include the trailing slash in your url, eg:

http://xxx.xxx.x.xx/hello.fcgi/

而不是

http://xxx.xxx.x.xx/hello.fcgi

这篇关于在 lighttpd 和树莓派上部署 Flask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆