"Empty reply from server" 用于 Flask + uWSGI 设置
"Empty reply from server" for Flask + uWSGI setup
我开始使用 WSGI,直到现在,在一些教程的帮助下,我正在对前面带有 uWSGI 的 Flask 进行一些测试,因为 Flask 不是生产环境的好选择(不能很好地扩展,默认情况下,它每次响应一个请求 - http://flask.pocoo.org/docs/0.12/deploying/)并且 uWSGI 提供了灵活性和更高的可靠性,产生了工作人员和进程。我错了吗?
我之前看到的大多数教程都指出在 WSGI 之前使用 Nginx 进行设置,但真的有必要吗?我想做的只是提供一种可扩展的方式来向我的 Flask 应用程序传递请求,它具有更高的性能和可扩展性。
所以我有这个基本设置:
hello.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080)
wsgi.py
from hello import app
if __name__ == "__main__":
app.run()
运行 uWSGI:
uwsgi --socket 0.0.0.0:8080 --plugin python --wsgi-file wsgi.py --callable app --master --processes 4 --threads 2 &
当我对环回地址执行 curl 时,收到空回复..
curl http://127.0.0.1:8080
invalid request block size: 21573 (max 4096)...skip
curl: (52) Empty reply from server
请原谅我,但我看不出我错过了什么。这里有没有人对 WSGI 更有经验,可以指出此设置的失败之处?如果有任何帮助,我将不胜感激。
参考文档:
https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-16-04
http://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html
当您将 uwsgi 与网络服务器(例如 nginx)结合使用时,应使用您的选项 socket
。否则你应该使用 http
,所以
uwsgi --http 0.0.0.0:8080 --plugin python --wsgi-file wsgi.py --callable app --master --processes 4 --threads 2
会起作用。
Production environments (doesn't scale well and by default, it answers
one request per time - http://flask.pocoo.org/docs/0.12/deploying/)
and uWSGI gives flexibility and more reliability, spawning workers and
processes. Am I wrong?
你是对的。
Most of the tutorials that I saw until, are pointing about setups with
Nginx in front of WSGI, but is it really necessary? What I'm trying to
do is just to give a scalable way to deliver requests to my Flask
application, something with more performance and scalability.
好吧,nginx 被设计为领先,拥有它比只有应用程序服务器 (uwsgi) 要好得多。专业化,这是关键。让您的应用服务器专注于业务处理和python.
我开始使用 WSGI,直到现在,在一些教程的帮助下,我正在对前面带有 uWSGI 的 Flask 进行一些测试,因为 Flask 不是生产环境的好选择(不能很好地扩展,默认情况下,它每次响应一个请求 - http://flask.pocoo.org/docs/0.12/deploying/)并且 uWSGI 提供了灵活性和更高的可靠性,产生了工作人员和进程。我错了吗?
我之前看到的大多数教程都指出在 WSGI 之前使用 Nginx 进行设置,但真的有必要吗?我想做的只是提供一种可扩展的方式来向我的 Flask 应用程序传递请求,它具有更高的性能和可扩展性。
所以我有这个基本设置:
hello.py
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=8080)
wsgi.py
from hello import app
if __name__ == "__main__":
app.run()
运行 uWSGI:
uwsgi --socket 0.0.0.0:8080 --plugin python --wsgi-file wsgi.py --callable app --master --processes 4 --threads 2 &
当我对环回地址执行 curl 时,收到空回复..
curl http://127.0.0.1:8080
invalid request block size: 21573 (max 4096)...skip
curl: (52) Empty reply from server
请原谅我,但我看不出我错过了什么。这里有没有人对 WSGI 更有经验,可以指出此设置的失败之处?如果有任何帮助,我将不胜感激。
参考文档: https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-16-04 http://uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html
当您将 uwsgi 与网络服务器(例如 nginx)结合使用时,应使用您的选项 socket
。否则你应该使用 http
,所以
uwsgi --http 0.0.0.0:8080 --plugin python --wsgi-file wsgi.py --callable app --master --processes 4 --threads 2
会起作用。
Production environments (doesn't scale well and by default, it answers one request per time - http://flask.pocoo.org/docs/0.12/deploying/) and uWSGI gives flexibility and more reliability, spawning workers and processes. Am I wrong?
你是对的。
Most of the tutorials that I saw until, are pointing about setups with Nginx in front of WSGI, but is it really necessary? What I'm trying to do is just to give a scalable way to deliver requests to my Flask application, something with more performance and scalability.
好吧,nginx 被设计为领先,拥有它比只有应用程序服务器 (uwsgi) 要好得多。专业化,这是关键。让您的应用服务器专注于业务处理和python.