我在这里不知所措......
我正在尝试使用 uwsgi 来运行我的 flask 应用程序。使用 WSGI Quick Start 处的示例我让它运行。
用于开发(restserver.py):
from api import app
if __name__ == '__main__':
app.run(debug=True, port=8080)
我该如何启动 uwsgi 服务器?
我试过这个(restserver.fcgi):
#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from api import app
if __name__ == '__main__':
WSGIServer(app, bindAddress='/var/run/fcgi.sock').run()
但是当阅读更多内容时,我发现 uwsgi 想要默认调用方法 application
。我当然可以更改它,但我没有 application
方法,所以在运行时:
/usr/local/bin/uwsgi --http :9090 --wsgi-file restserver.fcgi
我在启动日志中收到以下消息:
unable to find "application" callable in file restserver.fcgi
最佳答案
你只需要将启动命令更改为
/usr/local/bin/uwsgi --http :9090 --wsgi-file restserver.fcgi --callable app
或者将您在 restserver.fcgi
中导入 Flask 应用程序的方式更改为
#!/usr/bin/python
from flup.server.fcgi import WSGIServer
from api import app as application
if __name__ == '__main__':
WSGIServer(application, bindAddress='/var/run/fcgi.sock').run()
Docs on using uWSGI with Flask
PS:实际上你的 flask app
是 WSGI 应用。
关于python - nginx下运行python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18143175/