WSGI 、uwsgi、uWSGI、Nginx、flask在整个web程序访问中的作用和位置

WSGI: Web Server Gateway Interface,web服务器网关接口,一种描述web服务器(如nginx,uWSGI等服务器)如何与web应用程序(如用Django、Flask框架写的程序)通信的规范。

WSGI is a specification. uWSGI provides an implementation of the WSGI specification. WSGI是一种规范。uWSGI提供了WSGI规范的一种实现

uWSGI是一个全功能的HTTP服务器,实现了WSGI协议、uwsgi协议、http协议等。它要做的就是把HTTP协议转化成语言支持的网络协议。比如把HTTP协议转化成WSGI协议,让Python可以直接使用。

1. WSGI and uwsgi both ARE protocols, not servers. It is used to communicate with web servers for load balancing and especially to take advantage of extra features that pure HTTP can not provide. So far Nginx and Cherokee have implemented this protocol.
2. uWSGI is a server and one of the protocols it implements is WSGI (do not confuse the uwsgi protocol with the uWSGI server). WSGI is a Python specification. There are several implementations of the WSGI specification and it's intended to be used for more than just application servers/web servers, but there are quite a few WSGI application servers (ie. CherryPy, which also happens to have a production ready WSGI compliant web server, if you weren't confused enough already!).
3. Comparing uWSGI to WSGI is comparing oranges to apples.
It is generally best to run Python in a separate process from your main web server. That way, the web server can have lots of tiny threads that serve static content really fast, while your separate Python processes will be big and heavyweight and each be running their own Python interpreter. So plain WSGI is bad, because it bloats every single one of your nginx threads with a big Python interpreter. Using flup or gunicorn or uWSGI behind nginx is much better, because that frees up nginx to simply serve content, and lets you choose how many tiny light nginx threads to run, independently of your choice of how many heavyweight Python threads you bring up to serve dynamic content. People seem very happy with gunicorn at the moment, but any of those three options should work fine.
Going forward, it also frees you up to move the Python to another server when load starts to get serious

Nginx

Nginx是一个Web服务器其中的HTTP服务器功能和uWSGI功能很类似,但是Nginx还可以用作更多用途,比如最常用的反向代理功能。

Flask

Flask内置了一个WSGI服务器,可以用来开发期的调试。因为性能的原因,真正上线时需要使用其他的实现了WSGI协议的服务器。

参考

打印/导出
QR Code
QR Code wsgi_uwsgi_nginx_flask在整个web程序访问中的作用和位置 (generated for current page)