我正在我的树莓派上设置一个简单的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
上出现了一个错误。第一行看起来不对,所以我在fat arrow后面加了一组括号:
那个命令在/etc/init.d/lighttpd start
时报错。第一行看着有问题,所以我在那个Fat Arrow后面添加了一对括号:
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>"
当我使用/etc/init.d/lighttpd start
启动时,当前的lighttpd.conf
失败了。
proxy-pass
相同的方法。php-fpm已经有该服务运行,但对于Python,您需要安装一个专用服务器,如gunicorn
或uwsgi
,并将其配置为在指定端口上运行您的应用程序。 - Prahlad Yeri