python - nginx下运行python

标签 python flask uwsgi

我在这里不知所措......

我正在尝试使用 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/

相关文章:

Python 迭代器 : What does iglob( )'s Iterator provide over glob()' s list?

python - 自动重新加载 PythonAnywhere.com 上托管的 Python-Flask 应用程序

python - 使用after_request时如何获取状态码?

django - uwsgi导入错误: No module named os

python - 我可以使用 Docker 使用 pyinstaller 创建 exe 吗

python - 如何加载 caffe 模型并转换为 numpy 数组?

python - -753 在 `pd.Timestamp` 中的时区意味着什么

python - 使用 Docker 实例制作 Web 服务器 - 什么去哪里?

django - nginx > uwsgi > django 上的错误网关 (502),但只有一个 SOME 设备