FastCGI、Lighttpd和Flas

2024-04-20 14:59:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我在我的Raspberry Pi上设置了一个简单的web服务器,但我似乎无法正确地设置lighttpd、fastcgi和flask。

到目前为止,我已经经历了/etc/lighttpd/lighttpd.conf的一些迭代,最近的一次是

fastcgi.server = ("/test" =>
    "test" => (
        "socket" => "/tmp/test-fcgi.sock",
        "bin-path" => "/var/www/py/test.fcgi",
        "check-local" => "disable"
    )
)

/etc/init.d/lighttpd start上抛出一个错误。第一行看起来不对,所以我在粗箭头后面加了一组括号:

^{pr2}$

这并没有显示错误,但当我尝试连接时,我在Chrome中得到了ERR_CONNECTION_REFUSED。然后我试着去除"/test" =>,结果也有同样的问题。我也尝试了this question,中显示的配置,但出现了相同的问题。

/var/www/py/test.fgci中:

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

WSGIServer(app, bindAddress="/tmp/test-fcgi.sock").run()

/var/www/py/test.py中:

from flask import Flask
app = Flask(__name__)

@app.route("/test")
def hello():
    return "<h1 style='color:red'>&#9773; hello, comrade &#9773;</h1>"

当前的lighttpd.conf在我用/etc/init.d/lighttpd start启动时失败。


Tags: frompytestimportappflaskservervar
1条回答
网友
1楼 · 发布于 2024-04-20 14:59:38

对于Python部分,我不能真正帮助您,因为它超出了我的技能范围,但是,当将php作为fcgi服务器运行时,我将使用lighttpd.conf如下所示。在

fastcgi.server += ( ".php" =>
    ((
        "host" => "127.0.0.1",
        "port" => "9000",
        "broken-scriptfilename" => "enable"
    ))
)

因此,我假设python需要下面这样的内容。在

^{pr2}$

相关问题 更多 >