从不在同一网络上的设备连接Flask Web服务 [英] Connect a Flask webservice from a device which is not on the same network

查看:346
本文介绍了从不在同一网络上的设备连接Flask Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不是Web编程专家,对此了解甚少.我正在尝试在EC2实例(Windows Server 2012R2)上运行Web服务,并且该Web服务是使用Flask包以Python编写的.我可以从本地主机连接到我的Web服务.但是我要做的是从同一网络上的的远程系统进行连接.

I am not an expert in web programming and know very little about it. I am trying to run a webservice on an EC2 instance (Windows Server 2012R2) and the webservice is written in Python using Flask package. I am able to connect to my webservice from localhost. But what I want to do is to connect it from a remote system which is NOT on the same network.

我从链接中了解到,将线路更改为app.run(host='0.0.0.0')可使 SAME 网络上的所有设备连接到我的Web服务.但是就像我说的那样,我想通过相同网络上的系统进行连接.如何在Flask中做到这一点?另外我还没有安装Apache.是运行网络服务的必需的吗?

I learned from this link, that changing the line to app.run(host='0.0.0.0') will let all devices on SAME network to connect to my webservice. But like I said, I want to connect from a system which is NOT on the same network. How can I do that in Flask? Also I have not installed Apache. Is that necessary to run a webservice?

任何建议都会很有帮助.非常感谢.

Any suggestions would be really helpful. Thanks a lot.

推荐答案

让A成为您要连接的服务器.设B为您要连接的服务器,据我收集,该服务器有时是localhost.

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.

以下是特定于EC2的:您必须打开与特定IP的连接.检查您实例的安全设置.如果您向EC2实例添加了安全组,请向其添加IP或服务器IP.否则,请确保将B的IP列入白名单.

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.

我不能完全确定这是您想要的,但是如果所有人应该能够访问A,则应该在端口8000上运行Flask应用程序.如果 only B(可能还有您的本地主机)应该能够访问A,则忽略此段...

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...

自动地,是的.顺便说一句,这也是您应该指向的IP,以便其他服务器也可以连接.因此,在您的情况下,也请指向0.0.0.0.

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.

否,不需要Apache.您可以根据需要持久保存Flask开发服务器. (也就是,您可以使用python run.py并将该进程保留为"Web服务"运行).在这种情况下,您不需要Apache即可完成这项工作.从长远来看,您将希望Apache或Nginx运行您的Web服务.

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.

这是一个教程,您可以使用它来使用Python进行Apache2的安装.只需忽略MySQL部分:

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

这篇关于从不在同一网络上的设备连接Flask Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆