我正在我的 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'>☭ hello, comrade ☭</h1>"
当我用
lighttpd.conf
启动当前的 /etc/init.d/lighttpd start
时会失败。
我无法真正帮助您解决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"
))
)
考虑到您收到错误消息 ERR_CONNECTION_REFUSED,看来问题可能与不正确的身份验证或有限的权限有关,而不是语法问题。
可能性:
netstat --listen
或 lighttpd 日志。
fastcgi.server = ("/hello.fcgi" =>
((
"socket" => "/tmp/hello-fcgi.sock",
"bin-path" => "/var/www/demoapp/hello.fcgi",
"check-local" => "disable",
"max-procs" => 1
))
)
#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from yourapplication import app
if __name__ == '__main__':
WSGIServer(app, bindAddress="/tmp/test-fcgi.sock").run()
检查完所有可能性后,让我们看看会发生什么。