3

我现在在 CherryPy Cheroot WSGI 服务器上运行 Python 2.7 Flask 应用程序,使用 HTTP,如下所示。

from cheroot.wsgi import Server as WSGIServer
from cheroot.wsgi import PathInfoDispatcher as WSGIPathInfoDispatcher

from MyFlaskApp import app

d = WSGIPathInfoDispatcher({'/': app})
server = WSGIServer(('0.0.0.0', 80), d)

if __name__ == '__main__':
   try:
      server.start()
   except KeyboardInterrupt:
      server.stop()

我需要从这里迁移到 HTTPS 吗?我找到了以下说明,但它似乎不适用于我的应用程序。

from cheroot.server import HTTPServer
from cheroot.ssl.builtin import BuiltinSSLAdapter

HTTPServer.ssl_adapter = BuiltinSSLAdapter(
        certificate='cert/domain.crt', 
        private_key='cert/domain.key')

我可以将上述示例应用到 Cheroot 上的 Flask 应用程序吗?如果不是,那么 Cheroot 上用于 HTTPS 的 Flask 应用程序的简单示例是什么?

4

1 回答 1

4

我想出了必要的修改。关于 Cheroot 上带有 https 的 Flask 应用程序的信息不多,所以我想我会分享它。

from cheroot.wsgi import Server as WSGIServer
from cheroot.wsgi import PathInfoDispatcher as WSGIPathInfoDispatcher
from cheroot.ssl.builtin import BuiltinSSLAdapter

from MyFlaskApp import app

my_app = WSGIPathInfoDispatcher({'/': app})
server = WSGIServer(('0.0.0.0', 443), my_app)

ssl_cert = "[path]/myapp.crt"
ssl_key = "[path]/myapp.key"
server.ssl_adapter =  BuiltinSSLAdapter(ssl_cert, ssl_key, None)

if __name__ == '__main__':
   try:
      server.start()
   except KeyboardInterrupt:
      server.stop()
于 2019-03-26T23:37:48.613 回答