Search code examples
tornadoserver-name

How to define a server name in tornado


I'm just starting to use torando. I can run the standard "hello world" example:

import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
  def get(self):
    self.write("Hello, world")
application = tornado.web.Application([
     (r"/", MainHandler),
])
if __name__ == "__main__":
      application.listen(8888)
      tornado.ioloop.IOLoop.instance().start()

The server will be used only in an local network.

I can write in browser http//:192.168.0.20:8888 and get the "Hello world" page.

How can I create a server name (for example 'myHomeServer') and connect from browser using it: http://myHomeServer ? Thanks


Solution

  • If it is only to access it from the same machine:

    • in /etc/hosts, put:

      192.168.0.20 myhomeserver

    If you need to access it from multiple machines, 2 solutions:

    • put the same line in every machine's /etc/hosts
    • create an A record in a dns server in your local network

      more info here if you have a linux server in your network.

    In all these scenarios, you'll still have to add the port after the servername in your browser.