我不知所措…我正在尝试使用uwsgi运行我的flask应用程序.使用WSGI Quick Start处的示例,我可以运行它.对于开发(restserver.py):from api import appif __name__ == __main__:app.run(debug=True, port=8080)我将...

我不知所措…
我正在尝试使用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希望默认情况下调用方法应用程序.我当然可以更改它,但是没有和应用程序方法,因此在运行时可以:
/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应用程序是WSGI应用程序.
沃梦达教程
本文标题为:在Nginx下运行python


基础教程推荐
猜你喜欢
- Linux系统下python代码运行shell命令的方法 2023-09-03
- 基于Python创建语音识别控制系统 2023-08-11
- Python的函数使用示例详解 2023-08-08
- 通过Shell脚本调用python脚本时出现ImportError 2023-11-12
- Pygame库200行代码实现简易飞机大战 2023-08-04
- OpenCV+MediaPipe实现手部关键点识别 2023-08-11
- CentOS 7.5 安装 Python3.7 2023-09-03
- c-适用于Windows的python ncreduce 2023-11-12
- python-没有空闲子进程连接 2023-11-10
- Python的进程及进程池详解 2023-08-04