Search code examples
sshservertornado

Running a Tornado Web server (on an actual server, not just locally)


This is my first time I am working with a web server. I have a .py programme which is my Tornado server that successfully handles requests. I have tested it out on my local machine and then sent it to my hosting. I ran the programme in an SSH-session and it worked perfectly fine, but after I had quit the SSH-session, the Tornado server stopped. Now I would really like to know what is the right way to run the Tornado service on my server.


Solution

  • It primarily depends on he type of deployment you have in mind. If you have a full server available you can use supervisor, as suggested by billy_lu; for a more robust setup you may put your Tornado server behind Nginx acting as a load balancer.

    On the other hand, some providers don't give you full access, and require Python web apps to serve using the WSGI protocol; a good example is Google App Engine. In this case you need to wrap your Tornado app in a WSGIAdapter; something like this:

    if __name__ == '__main__':
        import tornado.httpserver
        http_server = tornado.httpserver.HTTPServer(app)
        http_server.listen(options.server_port, address=options.server_address)
        tornado.ioloop.IOLoop.instance().start()
    else:
        import tornado.wsgi
        app = tornado.wsgi.WSGIAdapter(app)