运行 通过 HTTPS 前夕
Run Eve over HTTPS
如何 运行 我的 Eve 应用程序通过 HTTPS 而不是 HTTP?
如果您正在 运行 直接查看您的 Eve 应用程序,没有像 nginx、apache 等真正的 Web 服务器,那么类似这样的东西会起作用:
import ssl
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.load_cert_chain('yourserver.crt', 'yourserver.key')
app.run(ssl_context=context, debug=True)
或者:
from OpenSSL import SSL
context = SSL.Context(SSL.SSLv23_METHOD)
context.use_privatekey_file('yourserver.key')
context.use_certificate_file('yourserver.crt')
app.run(ssl_context=context, debug=True)
现在,这两个选项可能都适合使用您自己的证书进行测试。您还可以使用 adhoc
快捷方式(可能需要安装 pyopenssl
):
app.run(ssl_context='adhoc', debug=True)
请记住,您真的不想 运行 在生产环境中使用它。您需要一个合适的服务器来执行此操作,并且它们都提供了有关如何为您的应用程序设置安全连接的适当文档。
如何 运行 我的 Eve 应用程序通过 HTTPS 而不是 HTTP?
如果您正在 运行 直接查看您的 Eve 应用程序,没有像 nginx、apache 等真正的 Web 服务器,那么类似这样的东西会起作用:
import ssl
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
context.load_cert_chain('yourserver.crt', 'yourserver.key')
app.run(ssl_context=context, debug=True)
或者:
from OpenSSL import SSL
context = SSL.Context(SSL.SSLv23_METHOD)
context.use_privatekey_file('yourserver.key')
context.use_certificate_file('yourserver.crt')
app.run(ssl_context=context, debug=True)
现在,这两个选项可能都适合使用您自己的证书进行测试。您还可以使用 adhoc
快捷方式(可能需要安装 pyopenssl
):
app.run(ssl_context='adhoc', debug=True)
请记住,您真的不想 运行 在生产环境中使用它。您需要一个合适的服务器来执行此操作,并且它们都提供了有关如何为您的应用程序设置安全连接的适当文档。