WSGI uWSGI uwsgi

三者区分

WSGI: Web Server Gateway Interface.是为Python语言定义的Web服务器和Web应用程序或框架之间的接口。WSGI是一种规范是一种通信协议。
uWSGI: 是一种web服务器。实现了WSGI,uwsgi,http等协议。
uwsgi: 是uWSGI专有的链路协议。

WSGI

WSGI标准下的HTTP处理函数模式

def application(environ, start_response):
    ...省略对该http请求所做的处理,生成状态码status,生成response_headers,生成response_body
    start_response(status, response_headers)
    # start_response('200 OK', [('Content-Type', 'text/html')])
    return response_body
    # return 'Hello World!'

start_response,是一个接收并处理响应状态码、response_headers的方法。
environ是一个包含所有HTTP请求信息的dict对象。
WSGI规定的environ数据传递字典内容示例:

{
    'HTTP_ACCEPT_LANGUAGE': 'zh-cn',
    'wsgi.file_wrapper': <built-infunctionuwsgi_sendfile>,
    'HTTP_UPGRADE_INSECURE_REQUESTS': '1',
    'uwsgi.version': b'2.0.15',
    'REMOTE_ADDR': '172.16.7.1',
    'wsgi.errors': <_io.TextIOWrappername=2mode='w'encoding='UTF-8'>,
    'wsgi.version': (1,0),
    'REMOTE_PORT': '40432',
    'REQUEST_URI': '/',
    'SERVER_PORT': '8000',
    'wsgi.multithread': False,
    'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'HTTP_HOST': '172.16.7.152: 8000',
    'wsgi.run_once': False,
    'wsgi.input': <uwsgi._Inputobjectat0x7f7faecdc9c0>,
    'SERVER_PROTOCOL': 'HTTP/1.1',
    'REQUEST_METHOD': 'GET',
    'HTTP_ACCEPT_ENCODING': 'gzip,deflate',
    'HTTP_CONNECTION': 'keep-alive',
    'uwsgi.node': b'ubuntu',
    'HTTP_DNT': '1',
    'UWSGI_ROUTER': 'http',
    'SCRIPT_NAME': '',
    'wsgi.multiprocess': False,
    'QUERY_STRING': '',
    'PATH_INFO': '/index.html',
    'wsgi.url_scheme': 'http',
    'HTTP_USER_AGENT': 'Mozilla/5.0(Macintosh;IntelMacOSX10_12_5)AppleWebKit/603.2.4(KHTML,likeGecko)Version/10.1.1Safari/603.2.4',
    'SERVER_NAME': 'centos7'
}
posted @ 2020-11-21 14:46  dsprain  阅读(94)  评论(0)    收藏  举报