Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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')
  • How to make connection via HTTPS?

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


  • Is it posible to use SPDY with Tornado? How? (I found TornadoSPDY on GitHub, but there are no explanations how to use it)

Any help appreciated

like image 474
MikeLP Avatar asked Oct 03 '22 09:10

MikeLP


1 Answers

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()
like image 191
Trausti Thor Avatar answered Oct 12 '22 12:10

Trausti Thor