FastCGI、Lighttpd 和 Flask

问题描述 投票:0回答:2

我正在我的 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
上吐出一个错误。第一行看起来不对,所以我在粗箭头后面添加了一组括号:

fastcgi.server = ("/test" => (
...
))

这并没有抛出错误,但当我尝试连接时,我在 Chrome 中得到

ERR_CONNECTION_REFUSED
。然后我尝试删除
"/test" =>
,但也出现了同样的问题。我也尝试过这个问题中显示的配置,并且出现了同样的问题。

/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
时会失败。

python flask lighttpd
2个回答
0
投票

我无法真正帮助您解决Python部分,因为它超出了我的技能范围,但是当将php作为fcgi服务器运行时,我会使用如下的lighttpd.conf。

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

所以我假设像下面这样的东西就是 python 所需要的。

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

0
投票

考虑到您收到错误消息 ERR_CONNECTION_REFUSED,看来问题可能与不正确的身份验证或有限的权限有关,而不是语法问题。

可能性:

  1. 检查lighttpd、fastcgi的运行端口状态。 (IPv6 检查)
    netstat --listen

或 lighttpd 日志。

  1. 您是否意识到您写了 '/test' => 'test',只需确保格式如下。
fastcgi.server = ("/hello.fcgi" =>
    ((
        "socket" => "/tmp/hello-fcgi.sock",
        "bin-path" => "/var/www/demoapp/hello.fcgi",
        "check-local" => "disable",
        "max-procs" => 1 
    ))
)
  1. 由于应用程序是从您的应用程序导入的,因此您需要将此行 'if name == 'main' 添加到 /var/www/py/test.fcgi 中。
#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from yourapplication import app

if __name__ == '__main__':
    WSGIServer(app, bindAddress="/tmp/test-fcgi.sock").run()

检查完所有可能性后,让我们看看会发生什么。

© www.soinside.com 2019 - 2024. All rights reserved.