SSLおよびWSGIアプリ-Python
質問
SSLの後ろに配置したいWSGIアプリがあります。私のWSGIサーバーはそうです Gevent.
この場合、SSLを通じてアプリを提供する良い方法は何でしょうか?
解決
GeventにはSSLモジュールがあるように見えます。 Geventの上にWebサーバーを実装している場合、HTTPハンドラーに渡す前に、そのモジュールのSSLソケットクラスとの着信接続をラップするように変更できると思います。
http://blog.gevent.org/2010/02/05/version-0-12-0-released/
http://www.gevent.org/gevent.ssl.html
それ以外の場合は、古き良きApache + mod_wsgiを使用してWSGIアプリを提供することができます。
他のヒント
Gevent.wsgi モジュールには、組み込みのSSLサポートがありません。使用している場合は、httpsを介してリクエストを受信するNginxの後ろに置いてください。
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()
HTTPサーバーにSSLトランスポートに対処させます。
所属していません StackOverflow