[Solved] Connect a Flask webservice from a device which is not on the same network


Let A be the server you connecting to. Let B be the server you are connecting from, which, from what I gather, is sometimes localhost.

Why can’t B connect to A?

1. Security Settings

The following is EC2-specific: You have to open up connections to specific IPs. Check your instance’s security settings. If you added a security group to your EC2 instance, add your IP or the IP of the server to it. Otherwise, make sure to whitelist the IP for B.

2. Port

I’m not entirely sure this is what you want, but if everyone should be able to access A, you should run the Flask app on port 8000. If only B (and possibly your localhost) should be able to access A, then ignore this paragraph…

0.0.0.0 allows devices on the SAME network to connect

Automagically, yes. Incidentally, this is the IP you should be pointing to, for other servers to connect too. So in your case, point to 0.0.0.0 too.

Is Apache necessary?

No, Apache is not necessary. You can persist a Flask development server if you want. (a.k.a. You can use python run.py and just leave that process running for a “web service”) In this case specifically, you don’t need Apache to make this work. In the long-term, you will want Apache or Nginx to run your webservice however.

Here’s a tutorial you can use to get Apache2 setup with Python. Just ignore the MySQL parts: https://www.digitalocean.com/community/tutorials/how-to-set-up-an-apache-mysql-and-python-lamp-server-without-frameworks-on-ubuntu-14-04

2

solved Connect a Flask webservice from a device which is not on the same network