Python uWSGI 的重点是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38601440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the point of uWSGI?
提问by d512
I'm looking at the WSGI specificationand I'm trying to figure out how servers like uWSGIfit into the picture. I understand the point of the WSGI spec is to separate web servers like nginx from web applications like something you'd write using Flask. What I don't understand is what uWSGI is for. Why can't nginx directly call my Flask application? Can't flask speak WSGI directly to it? Why does uWSGI need to get in between them?
我正在查看WSGI 规范,并试图弄清楚像uWSGI这样的服务器如何适应图片。我理解 WSGI 规范的重点是将像 nginx 这样的 Web 服务器与像你使用Flask编写的东西一样的 Web 应用程序分开。我不明白 uWSGI 的用途是什么。为什么 nginx 不能直接调用我的 Flask 应用程序?烧瓶不能直接说 WSGI 吗?为什么 uWSGI 需要介于它们之间?
There are two sides in the WSGI spec: the server and the web app. Which side is uWSGI on?
WSGI 规范有两个方面:服务器和 Web 应用程序。uWSGI 站在哪一边?
回答by d512
Okay, I think I get this now.
好的,我想我现在明白了。
Why can't nginx directly call my Flask application?
为什么 nginx 不能直接调用我的 Flask 应用程序?
Because nginx
doesn't support the WSGI spec. Technically nginx could implement the WSGI
spec if they wanted, they just haven't.
因为nginx
不支持 WSGI 规范。从技术上讲,WSGI
如果他们愿意,nginx 可以实现规范,但他们还没有。
That being the case, we need a web server that does implement the spec, which is what the uWSGI
server is for.
在这种情况下,我们需要一个实现规范的 Web 服务器,这就是uWSGI
服务器的用途。
Note that uWSGI
is a full fledged http server that can and does work well on its own. I've used it in this capacity several times and it works great. If you need super high throughput for static content, then you have the option of sticking nginx
in front of your uWSGI
server. When you do, they will communicate over a low level protocol known as uwsgi
.
请注意,这uWSGI
是一个成熟的 http 服务器,它可以并且确实可以很好地独立运行。我已经多次以这种身份使用它,而且效果很好。如果您需要静态内容的超高吞吐量,那么您可以选择坚持nginx
在您的uWSGI
服务器前。当您这样做时,他们将通过称为uwsgi
.
"What the what?! Another thing called uwsgi?!"you ask. Yeah, it's confusing. When you reference uWSGI
you are talking about an http server. When you talk about uwsgi
(all lowercase) you are talking about a binary protocolthat the uWSGI
serveruses to talk to other servers like nginx
. They picked a bad name on this one.
“什么什么?!还有一种叫做uwsgi的东西?!” 你问。是的,很混乱。当您引用时,uWSGI
您是在谈论 http 服务器。当你谈论uwsgi
(全部小写),你是在谈论一个二进制协议,该uWSGI
服务器使用跟其他服务器一样nginx
。他们在这个名字上取了一个坏名字。
For anyone who is interested, I wrote a blog articleabout it with more specifics, a bit of history, and some examples.
回答by alejandrodnm
NGINX in this case only works as a reverse proxy and render static files not the dynamic files, it receives the requests and proxies them to the application server, that would be UWSGI.
在这种情况下,NGINX 仅用作反向代理并呈现静态文件而不是动态文件,它接收请求并将它们代理到应用程序服务器,即 UWSGI。
The UWSGI server is responsible for loading your Flask application using the WSGI interface. You can actually make UWSGI listen directly to requests from the internet and remove NGINX if you like, although it's mostly used behind a reverse proxy.
UWSGI 服务器负责使用 WSGI 接口加载您的 Flask 应用程序。实际上,您可以让 UWSGI 直接侦听来自 Internet 的请求并根据需要删除 NGINX,尽管它主要用于反向代理。
From the docs:
从文档:
uWSGI supports several methods of integrating with web servers. It is also capable of serving HTTP requests by itself.
uWSGI 支持多种与 Web 服务器集成的方法。它还能够自行处理 HTTP 请求。
WSGI is just an interface specification, in simple terms, it tells you what methods should be implemented for passing requests and responses between the server and the application. When using frameworks such as Flask or Django, this is handled by the framework itself.
WSGI 只是一个接口规范,简单来说就是告诉你应该实现哪些方法来在服务器和应用程序之间传递请求和响应。当使用 Flask 或 Django 等框架时,这由框架本身处理。
In other words, WSGI is basically a contract between python applications (Flask, Django, etc) and web servers (UWSGI, Gunicorn, etc). The benefit is that you can change web servers with little effort because you know they comply with the WSGI specification, which is actually one of the goals, as stated in PEP-333.
换句话说,WSGI 基本上是 Python 应用程序(Flask、Django 等)和 Web 服务器(UWSGI、Gunicorn 等)之间的契约。好处是您可以毫不费力地更改 Web 服务器,因为您知道它们符合 WSGI 规范,这实际上是目标之一,如PEP-333 中所述。
Python currently boasts a wide variety of web application frameworks, such as Zope, Quixote, Webware, SkunkWeb, PSO, and Twisted Web -- to name just a few 1. This wide variety of choices can be a problem for new Python users, because generally speaking, their choice of web framework will limit their choice of usable web servers, and vice versa.
Python 目前拥有多种 Web 应用程序框架,例如 Zope、Quixote、Webware、SkunkWeb、PSO 和 Twisted Web —— 仅举几例1。对于 Python 新用户来说,这种多样化的选择可能是一个问题,因为一般来说,他们对 Web 框架的选择会限制他们对可用 Web 服务器的选择,反之亦然。
回答by Rafiqul Hasan
A traditional web server does not understand or have any way to run Python applications. That's why WSGI server come in. On the other hand Nginx supports reverse proxy to handle requests and pass back responses for Python WSGI servers.
传统的 Web 服务器不理解或无法运行 Python 应用程序。这就是 WSGI 服务器进来的原因。另一方面,Nginx 支持反向代理来处理请求并为 Python WSGI 服务器传回响应。
This link might help you: https://www.fullstackpython.com/wsgi-servers.html
此链接可能对您有所帮助:https: //www.fullstackpython.com/wsgi-servers.html