在Nginx下运行python教程
我不知所措…
我正在尝试使用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应用程序.