Please help me to create HTTPS tornado server My current code Python3 doesn't work
import os, socket, ssl, pprint, tornado.ioloop, tornado.web, tornado.httpserver from tornado.tcpserver import TCPServer class getToken(tornado.web.RequestHandler): def get(self): self.write("hello") application = tornado.web.Application([ (r'/', getToken), ]) # implementation for SSL http_server = tornado.httpserver.HTTPServer(application) TCPServer(ssl_options={ "certfile": os.path.join("/var/pyTest/keys/", "ca.csr"), "keyfile": os.path.join("/var/pyTest/keys/", "ca.key"), }) if __name__ == '__main__': #http_server.listen(8888) http_server = TCPServer() http_server.listen(443) tornado.ioloop.IOLoop.instance().start()
HTTPS is very important for me, please help
If you want to daemonize tornado - use supervisord. If you want to access tornado on address like http://mylocal.dev/ - you should look at nginx and use it like reverse proxy. And on specific port it can be binded like in Lafada's answer.
Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.
Tornado is a Python web framework and asynchronous network library, originally developed at FriendFreed. Tornado uses non-blocking network-io. Due to this, it can handle thousands of active server connections. It is a saviour for applications where long polling and a large number of active connections are maintained.
No need to use TCPServer
.
Try following:
import tornado.httpserver import tornado.ioloop import tornado.web class getToken(tornado.web.RequestHandler): def get(self): self.write("hello") application = tornado.web.Application([ (r'/', getToken), ]) if __name__ == '__main__': http_server = tornado.httpserver.HTTPServer(application, ssl_options={ "certfile": "/var/pyTest/keys/ca.csr", "keyfile": "/var/pyTest/keys/ca.key", }) http_server.listen(443) tornado.ioloop.IOLoop.instance().start()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With