MikeLP
MikeLP

Reputation: 198

How run bottle + tornado + ssl (https) + spdy

I'm using python framework bottle with webserver tornado. Here's my init.py:

import bottle
import os

# Init application
bottle.run(host="127.0.0.1", app=app, port=int(os.environ.get("PORT", 5000)), server='tornado')

I read this article http://dgtool.blogspot.com/2011/12/ssl-encryption-in-python-bottle.html but it's about CherryPy server.



Any help appreciated

Upvotes: 5

Views: 1496

Answers (1)

Trausti Thor
Trausti Thor

Reputation: 3774

Your best bet would be to use a proxy front end server like nginx, haproxy or apache. Configuring tornado with ssl is extremely slow, it slows tornado down to a crawl until it becomes totally unresponsive with just minimal visits. I have looked everywhere to get a decent speed in ssl traffic using tornado directly, but did not find any. Besides it is not bad to use a front end server.

But by using apache f.ex. as a front end proxy, I got close to native non-ssl speeds.

But to configure tornado with ssl, is simple :

def main():
    handlers = [
        (r"/", HomeHandler),
    ]
    settings = dict(
       blog_title=u"Tornado Blog",
        template_path=os.path.join(os.path.dirname(__file__), "templates"),
        static_path=os.path.join(os.path.dirname(__file__), "static"),
        cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
        debug=True,
        certfile = os.path.join("certs/server.crt"),
        keyfile = os.path.join("certs/server.key"),
        ssl_options = {
            "certfile" : os.path.join("certs/server.crt"),
            "keyfile" : os.path.join("certs/server.key"),
        },
    )
    tornado.options.parse_command_line()
    http_server = tornado.httpserver.HTTPServer(Application())
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()

main()

Upvotes: 4

Related Questions