如果 Tornado Python 对 HTTP 的请求可以自动重定向到 HTTPS,那就太好了。
有没有办法做到这一点?
- 蟒蛇 3v
- 龙卷风 3.1v
更新
新的解决方案,但是...我可以做错什么吗(
http:// IP_ADDRESS :4443/
警告:tornado.general:SSL 错误 8 ('IP_ADDRESS', 51453): [SSL: HTTP_REQUEST] http 请求 (_ssl.c:547)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import tornado.ioloop
import tornado.web
import tornado.httpserver
import http.server
class MainHandler(tornado.web.RequestHandler):
def prepare(self):
if self.request.protocol == "http":
self.redirect("https://%s" % self.request.full_url()[len("http://"):], permanent=True)
def get(self):
self.write("Hello, world")
application = tornado.web.Application([
(r'/', MainHandler),
])
http_server = tornado.httpserver.HTTPServer(application,
ssl_options = {
"certfile": os.path.join("/var/pyTest/keys/", "cert.pem"),
"keyfile": os.path.join("/var/pyTest/keys/", "key.pem"),
}
)
if __name__ == '__main__':
http_server.listen(4443)
tornado.ioloop.IOLoop.instance().start()