تطبيقات SSL و WSGI - Python
سؤال
لدي تطبيق WSGI أود وضعه خلف SSL. خادم WSGI الخاص بي جيفنت.
ما هي الطريقة الجيدة لخدمة التطبيق من خلال SSL في هذه الحالة؟
المحلول
يبدو أن Gevent الآن لديه وحدة SSL. إذا كان لديك خادم ويب تم تنفيذه فوق Gevent ، أتصور أنه يمكنك تعديله لالتفاف اتصالات واردة بفئة مقبس 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 الخاص بك.
نصائح أخرى
ال gevent.wsgi الوحدة النمطية لا تحتوي على دعم SSL مدمج. إذا كنت تستخدمه ، فضعها خلف Nginx والتي ستتلقى طلبًا عبر HTTPS ولكن وكيلها إلى تطبيق Gevent الخاص بك باستخدام HTTP غير المشفرة.
ال 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.