使用uWSGI服务一个简单的wsgi应用程序(一个简单的“Hello,World”)我的configuration工作,但是当我尝试运行一个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 ***`
特别注意这部分日志:
无法find文件/var/www/coefficient/flask.py中可调用的“应用程序”
无法加载应用程序0(安装点='')(可调用未find或导入错误)
******没有加载应用程序。 进入完全dynamic模式
这是我的Flask应用程序:
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello, World, from Flask!"
在将我的Virtualenv的pythonpath添加到我的configuration文件之前,我得到了一个Flask的ImportError。 我解决了这个,但我相信(我没有收到有关它的错误),这里是我的完整的configuration文件:
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
任何帮助表示赞赏。
无法find文件/var/www/coefficient/flask.py中可调用的“应用程序”
是关键:)
您的应用正在定义可调用的“应用”,因此您必须指示uWSGI对其进行search,而不是“应用”。
您可以使用该选项
callable: app
它会起作用(这在官方的Flask文档中有解释)
或者,你可以添加module = flaskapp:app到你的ini。
另外, uwsgi-docs中的 callable函数更加清晰:
Flask将它的WSGI函数(在这个快速入门的开头叫做“application”)作为“app”导出,所以我们需要指示uWSGI使用它:
uwsgi --wsgi-file myflaskapp.py --callable app