该gevent.wsgi模块不具有内置的SSL支持.如果您正在使用它,请将其放在nginx后面,该nginx将通过HTTPS接收请求,但使用非加密HTTP将它们代理到您的gevent应用程序.
该gevent.pywsgi模块是否有内置的SSL支持,并具有兼容的接口.设置keyfile和certfile参数以使服务器使用SSL.这是一个例子:wsgiserver_ssl.py:
#!/usr/bin/python
"""Secure WSGI server example based on gevent.pywsgi"""
from __future__ import print_function
from gevent import pywsgi
def hello_world(env, start_response):
if env['PATH_INFO'] == '/':
start_response('200 OK', [('Content-Type', 'text/html')])
return [b"<b>hello world</b>"]
else:
start_response('404 Not Found', [('Content-Type', 'text/html')])
return [b'<h1>Not Found</h1>']
print('Serving on https://127.0.0.1:8443')
server = pywsgi.WSGIServer(('0.0.0.0', 8443), hello_world, keyfile='server.key', certfile='server.crt')
# to start the server asynchronously, call server.start()
# we use blocking serve_forever() here because we have no other jobs
server.serve_forever()
Run Code Online (Sandbox Code Playgroud)
看起来 gevent 现在有一个 ssl 模块。如果您有一个在 gevent 之上实现的 Web 服务器,我想您可以修改它以将传入连接包装到该模块的 ssl 套接字类,然后再将其传递给 http 处理程序。
http://blog.gevent.org/2010/02/05/version-0-12-0-released/
http://www.gevent.org/gevent.ssl.html
否则,您始终可以使用旧的 apache + mod_wsgi 来为您的 wsgi 应用程序提供服务。
| 归档时间: |
|
| 查看次数: |
5034 次 |
| 最近记录: |