ls0f / my-issues

0 stars 0 forks source link

WSGI #18

Open ls0f opened 8 years ago

ls0f commented 8 years ago

什么是WSGI

Web服务器网关接口(Python Web Server Gateway Interface,缩写为WSGI)是为Python语言定义的Web服务器和Web应用程序或框架之间的一种简单而通用的接口。自从WSGI被开发出来以后,许多其它语言中也出现了类似接口。

WSGI is not a server, a python module, a framework, an API or any kind of software. It is just an interface specification by which server and application communicate. Both server and application interface sides are specified in the PEP 3333. If an application (or framework or toolkit) is written to the WSGI spec then it will run on any server written to that spec.

也就是说WSGI仅仅是一个web server和application沟通的工具而已

那什么是WSGI server呢?顾名思义就是支持WSGI沟通工具的HTTP server。

WSGI的目的

我认为是保持KISS原则。各个模块专注于做自己的事情。应用开发框架做好自己的URL路由处理、HTML模板等,WSGI server专注于连接处理、并发,各司其职。

常见的应用程序开发框架有:

常见的WSGI server有:

Tornado比较特殊,既可以作为application跑在WSGI server的后面,又可以自己作为WSGI server去运行其它的application,当然也可以直接作为HTTP server(不用WSGI沟通)运行。

为什么还需要Nginx

既然WSGI server可以直接作为HTTP server运行,为什么我们大都在前面加一个Nginx代理呢?有很多原因,比如可以用Nginx负载均衡将请求转发到不同的HTTP server后面、对静态资源处理的更高效、更安全可靠等。

参考

http://wsgi.tutorial.codepoint.net/intro https://www.digitalocean.com/community/tutorials/a-comparison-of-web-servers-for-python-based-web-applications

ls0f commented 8 years ago

全文看这里:https://github.com/lovedboy/blog-md/blob/master/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/wsgi.md