使用 uWSGI 提供一个简单的 wsgi 应用程序(一个简单的“Hello, World”)我的配置有效,但是当我尝试运行 Flask 应用程序时,我在 uWSGI 的错误日志中得到了这个:
current working directory: /opt/python-env/coefficient/lib/python2.6/site-packages
writing pidfile to /var/run/uwsgi.pid
detected binary path: /opt/uwsgi/uwsgi
setuid() to 497
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to TCP address 127.0.0.1:3031 fd 3
Python version: 2.6.6 (r266:84292, Jun 18 2012, 14:18:47) [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)]
Set PythonHome to /opt/python-env/coefficient/
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xbed3b0
your server socket listen backlog is limited to 100 connections
*** Operational MODE: single process ***
added /opt/python-env/coefficient/lib/python2.6/site-packages/ to pythonpath.
unable to find "application" callable in file /var/www/coefficient/flask.py
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***`
特别注意日志的这一部分:
无法在文件 /var/www/coefficient/flask.py 中找到可调用的“应用程序”
无法加载应用程序 0 (mountpoint='')(找不到可调用文件或导入错误)
******没有加载应用程序。进入全动态模式******
这是我的烧瓶应用程序:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello, World, from Flask!"
在我将我的 Virtualenv 的 pythonpath 添加到我的配置文件之前,我收到了 Flask 的 ImportError。虽然我解决了这个问题,但我相信(我不再收到有关它的错误)这是我完整的配置文件:
uwsgi:
#socket: /tmp/uwsgi.sock
socket: 127.0.0.1:3031
daemonize: /var/log/uwsgi.log
pidfile: /var/run/uwsgi.pid
master: true
vacuum: true
#wsgi-file: /var/www/coefficient/coefficient.py
wsgi-file: /var/www/coefficient/flask.py
processes: 1
virtualenv: /opt/python-env/coefficient/
pythonpath: /opt/python-env/coefficient/lib/python2.6/site-packages
这就是我从 rc 脚本启动 uWSGI 的方式:
/opt/uwsgi/uwsgi --yaml /etc/uwsgi/conf.yaml --uid uwsgi
如果我尝试在浏览器中查看 Flask 程序,我会得到:
**uWSGI Error**
Python application not found
任何帮助表示赞赏。
是关键:)
你的应用程序正在定义一个'app'可调用,所以你必须指示uWSGI搜索它,而不是'application'。
您可以使用该选项
callable: app
它会起作用(这在 Flask 官方文档中有解释)
或者,您可以添加
module = flaskapp:app
到您的 ini。此外,事实上,
callable
在uwsgi-docs 中更清楚地解决了: