Multi-server SSL with CherryPy
It’s quite hard to see in the CherryPy docs how to support http and https from a single app. It turns out combining a few of the posts on the tools wiki is the way to go.
Starting the app looks like:
if __name__ == "__main__": from cherrypy import _cpserver from cherrypy import _cpwsgi_server secure_server = _cpwsgi_server.CPWSGIServer() cherrypy.config.namespaces['secure_server'] = lambda k, v: setattr(secure_server, k, v) secure_server.bind_addr = ('0.0.0.0', cherrypy.config['secure_server.socket_port']) adapter = _cpserver.ServerAdapter(cherrypy.engine, secure_server, secure_server.bind_addr) adapter.subscribe() app = cherrypy.Application(Root()) app.wsgiapp.pipeline.append(('repoze.who', setup_auth)) app.wsgiapp.pipeline.append(('beaker', setup_session_storage)) cherrypy.quickstart(app, config='workbench.conf')
And the important config file options are:
[global] server.socket_host = "0.0.0.0" server.socket_port = 8080 server.thread_pool = 10 secure_server.socket_port = 8443 secure_server.ssl_certificate = "certs/self_sign_certificate.crt" secure_server.ssl_private_key = "certs/self_sign.key"
Loki
Leave a Reply
Want to join the discussion?Feel free to contribute!