【问题标题】:Tornado SSL certsTornado SSL 证书
【发布时间】:2014-01-05 07:59:07
【问题描述】:

我有一个关于 tornado SSL 配置的问题。我想处理 HTTPS 协议。我还阅读了文档和 stackoverflow 相同的问题。我有一个 SSL 证书和密钥文件。代码看起来像

settings = dict(
    ...
    ssl_options = {
        "certfile": os.path.join("certs/myserver.crt"),
        "keyfile": os.path.join("certs/myserver.key"),
    },
    ...
)
def main():
    http_server = tornado.httpserver.HTTPServer(tornado.web.Application(handlers,
                  **settings))

    http_server.listen(443)
    tornado.ioloop.IOLoop.instance().start()

在我启动我的应用程序之后。我想从浏览器https://mydomain.com 访问,但它不工作,什么也没发生,它给出了不成功的请求错误。我该怎么办?顺便说一句,http://mydomain.com:443 正在工作。

【问题讨论】:

    标签: python ssl nginx openssl tornado


    【解决方案1】:

    您将设置传递给 tornado.web.Application() 而不是 tornado.httpserver.HTTPServer

    试试这个,

    settings = dict(
        ...
        ssl_options = {
            "certfile": os.path.join("certs/myserver.crt"),
            "keyfile": os.path.join("certs/myserver.key"),
        },
        ...
    )
    def main():
        http_server = tornado.httpserver.HTTPServer(tornado.web.Application(handlers), 
                      ssl_options = {
        "certfile": os.path.join("certs/myserver.crt"),
        "keyfile": os.path.join("certs/myserver.key"),
    })
    
        http_server.listen(443)
        tornado.ioloop.IOLoop.instance().start()
    

    更新:

    settings = dict(
        ...
        ssl_options = {
            "certfile": os.path.join("certs/myserver.crt"),
            "keyfile": os.path.join("certs/myserver.key"),
        },
        ...
    )
    def main():
        http_server = tornado.httpserver.HTTPServer(tornado.web.Application(handlers), **settings)
    
        http_server.listen(443)
        tornado.ioloop.IOLoop.instance().start()
    

    【讨论】:

    • Praveen 谢谢你的回答,但是其他设置呢?
    • 在设置字典中有关键参数,例如 template_path。现在龙卷风给出了 TypeError: __init__() got an unexpected keyword argument 'template_path' 错误
    • 普拉文谢谢你。我做到了。你给了我明确的方向
    • 创建密钥的最简单方法是运行“ openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout certs/myserver.crt.key -out certs/myserver.crt.pem " 基于jupyter-notebook.readthedocs.io/en/latest/public_server.html 感谢 Praveen 的回答。
    猜你喜欢
    • 2014-10-19
    • 2018-08-23
    • 2017-06-13
    • 2019-03-29
    • 2013-01-25
    • 2012-04-13
    • 2015-07-16
    • 2012-12-21
    相关资源
    最近更新 更多