57

I am reading the Flask documentation. I was told that with app.run(host='0.0.0.0'), I could make the server publicly available.

What does it mean ? How can I visit the server in another computer (just localhost:5000 in my own computer) ?

Anto
  • 6,806
  • 8
  • 43
  • 65
Ding
  • 579
  • 1
  • 4
  • 4
  • 0.0.0.0 equal to bind all interfaces. Otherwise bind only one (10.0.0.4) – dsgdfg Aug 09 '15 at 13:35
  • But you would need to forward the port on your router to your dev machine, and give the world your public IP address (usually that means pointing a domain name at it, via DNS). – Jonathon Reinhart Aug 09 '15 at 13:38

1 Answers1

30

To answer to your second question. You can just hit the IP address of the machine that your flask app is running, e.g. 192.168.1.100 in a browser on different machine on the same network and you are there. Though, you will not be able to access it if you are on a different network. Firewalls or VLans can cause you problems with reaching your application. If that computer has a public IP, then you can hit that IP from anywhere on the planet and you will be able to reach the app. Usually this might impose some configuration, since most of the public servers are behind some sort of router or firewall.

ipinak
  • 5,739
  • 3
  • 23
  • 41
  • But I cannot visit on another machine... – Ding Aug 10 '15 at 08:50
  • I have closed the firewall. My external IP address is 115.XXX.XXX.XXX , I visited http://115.XXX.XXX.XXX:5000 on another computer. It didn't work. – Ding Aug 10 '15 at 08:52
  • 2
    Setup nginx (or some other web server) and connect your internal IP e.g. `192.168.1.100` to the web server. For nginx check here: http://nginx.org/en/docs/http/ngx_http_upstream_module.html. Let me know if you get stack. – ipinak Aug 10 '15 at 19:31
  • 2
    By any chance do you know why setting it to 0.0.0.0 allows different machine to access the website? what exactly is it that is special about this 0.0.0.0 ? – variable Feb 12 '20 at 08:08
  • @variable: That arg tells Flask which IP address(es) to listen on. If I have a server with multiple IP addresses, I might only want the app to bind to (and listen for requests on) one of those. I believe `0.0.0.0` is just a placeholder value to say "This isn't actually a real IP address I'm passing - just listen on ANY IP addresses on this host". The `0.0.0.0` terminology probably harkens back to a netmask setting of the same, which means similarly , "all ip addresses" (that's just a guess on my part though). See https://flask.palletsprojects.com/en/1.1.x/api/?highlight=run#flask.Flask.run – loneboat Jul 21 '20 at 01:43