Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a Flask app on CherryPy WSGI server (Cheroot) using HTTPS?

I am running a Python 2.7 Flask app on CherryPy Cheroot WSGI server usinh HTTP now as below.

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()

What would I have to to move to HTTPS from here? I found below instruction, but it does not seem to applicable to my application.

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

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

Can I apply above sample to my Flask app on Cheroot? If not, what would be a simple example for Flask app on Cheroot for HTTPS?

like image 774
Kay Avatar asked Mar 05 '26 14:03

Kay


1 Answers

I figured out the necessary modification. Not much information on Flask app on Cheroot with https, so I thought I'd share it.

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()
like image 65
Kay Avatar answered Mar 08 '26 03:03

Kay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!