WSGI是Web Service Gateway Interface的缩写。

WSGI标准在PEP(Python Enhancement Proposal)中定义并被许多框架实现,其中包括现广泛使用的django框架。

PythonWeb服务器接口(Python Web Server Gateway Interface,缩写为WSGI)是Python应用程序或框架和Web服务器之间的一种接口,已经被广泛接受, 它已基本达成它的可移植性方面的目标。

Nova使用了eventlet.wsgi接口。

"""This is a simple example of running a wsgi application with eventlet.
For a more fully-featured server which supports multiple processes,
multiple threads, and graceful code reloading, see: http://pypi.python.org/pypi/Spawning/
""" import eventlet
from eventlet import wsgi def hello_world(env, start_response):
if env['PATH_INFO'] != '/':
start_response('404 Not Found', [('Content-Type', 'text/plain')])
return ['Not Found\r\n']
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['Hello, World!\r\n'] wsgi.server(eventlet.listen(('', 8090)), hello_world)

SSL方式(Secure Socket Layer)

wsgi.server(eventlet.wrap_ssl(eventlet.listen(('', 8090)),
certfile='cert.crt',
keyfile='private.key',
server_side=True),
hello_world)

流程描述:

服务器开一个socket等待客户端连接;请求来了,服务器会读出传来的数据,然后根据HTTP协议做一些初步的封装,

接着就可以调用事先注册的应用程序了,并将请求的数据塞进去;等响应处理完毕了再把数据通过socket发出去

server参数介绍:

def server(sock,  # Server socket, must be already bound to a port and listening(IP和端口并开启监听).
site, # WSGI application function(事件处理函数,发送start_response响应头然后返回响应内容)
log=None, # File-like object that logs should be written to.If not specified, sys.stderr is used.(日志处理,默认为sys.stderr用来重定向标准错误信息的)
environ=None, # Additional parameters that go into the environ dictionary of every request(每次请求的参数,写入一个字典中)
max_size=None, #Maximum number of client connections opened at any time by this server.(默认为1024)
max_http_version=DEFAULT_MAX_HTTP_VERSION, # Set to "HTTP/1.0" to make the server pretend it only supports HTTP 1.0.
                                # This can help with applications or clients that don't behave properly using HTTP 1.1.(HTTP协议版本,默认为HTTP/1.1)
protocol=HttpProtocol, # Protocol class.(协议类,默认为HttpProtocol)
server_event=None, # Used to collect the Server object(搜集服务器对象信息)
minimum_chunk_size=None, # Minimum size in bytes for http chunks.  This can be used to improve performance of applications which yield many small strings, though
                      # using it technically violates the WSGI spec. This can be overridden on a per request basis by setting environ['eventlet.minimum_write_chunk_size'].
                      # 设置最小的Chunk大小,可以通过设置environ['eventlet.minimum_write_chunk_size']来覆盖.Chunk表示服务器发送给客户端的分块传输编码(Chunked transfer encoding)
log_x_forwarded_for=True, # If True (the default), logs the contents of the x-forwarded-for header in addition to the actual client ip address in the 'client_ip' field of the log line.
                      # 默认为True,记录客户端IP日志,X-Forwarded-For(XFF)是用来识别通过HTTP代理或负载均衡方式连接到Web服务器的客户端最原始的IP地址的HTTP请求头字段。
custom_pool=None, # A custom GreenPool instance which is used to spawn client green threads.If this is supplied, max_size is ignored.(协程池,如果启用则可以忽略前面的max_size参数)
keepalive=True, # If set to False, disables keepalives on the server; all connections will be closed after serving one request.(控制客户端连接数是否保持alive)
log_output=True, # A Boolean indicating if the server will log data or not.(确定服务端是否输出日志)
log_format=DEFAULT_LOG_FORMAT, # A python format string that is used as the template to generate log lines.(日志输出格式)
url_length_limit=MAX_REQUEST_LINE, # A maximum allowed length of the request url. If exceeded, 414 error is returned.(最大的url长度限制,默认为8192)
debug=True, # True if the server should send exception tracebacks to the clients on 500 errors.If False, the server will respond with empty bodies.(是否发送调式信息给客户端)
socket_timeout=None, # Timeout for client connections' socket operations. Default None means wait forever.(Socket超时时间设置,单位是秒)
capitalize_response_headers=True) # Normalize response headers' names to Foo-Bar(是否标准化相应头)

最新文章

  1. bootstrap分页
  2. url的路径设置问题
  3. 【POJ】3133 Manhattan Wiring
  4. 【BZOJ】1221: [HNOI2001] 软件开发(最小费用最大流)
  5. Java 使用jaxp添加节点
  6. python_way day12 sqlalchemy,原生mysql命令
  7. HD1085 Holding Bin-Laden Captive!
  8. MongoDB 安装与启动
  9. 使用CXF开发JAX-RS类型的WebService
  10. 浅谈 MongoDB
  11. C#项目 学生选课系统 C#窗口 Winform项目 项目源码及使用说明
  12. SQL语句和EF Group by 用法
  13. hdu 2586 How far away ? 倍增求LCA
  14. javascript 浮点数加减乘除计算会有问题, 整理了以下代码来规避这个问题
  15. idea中xml打开方式变成file,改回来
  16. Java实现的词频统计——功能改进
  17. 那么类 Man 可以从类 Human 派生,类 Boy 可以从类 Man 派生
  18. 1001 害死人不偿命的(3n+1)猜想 (15 分)
  19. MyEclipse - 问题集 - build properties does not exist
  20. Android 两种注册、发送广播的区别

热门文章

  1. jQuery 文档操作 - html() 方法
  2. jquery 键盘事件的使用方法详解
  3. k8s基础(3)etcd集群
  4. shell入门-awk-2
  5. OpenCV创建轨迹条,图片像素的访问
  6. React中state和props的区别
  7. CentOS 6.5 and Ubuntu 14.04 使用外部邮箱发送邮件
  8. hadoop-maven项目打包成可执行的jar
  9. crontab简易入门
  10. Jmeter连接MySQL配置(能执行多条sql语句)