search

Home  >  Q&A  >  body text

python - Tornado只能在127.0.0.1监听吗?

刚刚开始学习Tornado,只在文档里看到可以设置端口,没看到设置IP的内容,难道必须要用Nginx转发???

PHP中文网PHP中文网2807 days ago933

reply all(4)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 17:24:09

    For reference only, it can be bound to 0.0.0.0, and then it can be accessed from the external network. The IP is the host address

    def main():
        parse_options()
        http_server = tornado.httpserver.HTTPServer(Application(),xheaders=True)
        print "Server started on port "+str(options.port)
        http_server.bind(int(options.port), "0.0.0.0")# listen local only "127.0.0.1"
        http_server.start(1)
        tornado.ioloop.IOLoop.instance().start()
    
    
    if __name__ == '__main__':
        main()

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 17:24:09

    Listen to 0.0.0.0

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 17:24:09

    Listening 0.0.0.0

    reply
    0
  • 阿神

    阿神2017-04-17 17:24:09

    Application’s listen method can specify IP, such as

    app.listen(8888, address="0.0.0.0")

    reply
    0
  • Cancelreply